35 require_once DOL_DOCUMENT_ROOT.
'/core/class/commonobject.class.php';
36 require_once DOL_DOCUMENT_ROOT.
"/core/class/commonobjectline.class.php";
37 require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
38 require_once DOL_DOCUMENT_ROOT.
'/margin/lib/margins.lib.php';
48 public $element =
'contrat';
53 public $table_element =
'contrat';
58 public $table_element_line =
'contratdet';
63 public $fk_element =
'fk_contrat';
68 public $picto =
'contract';
74 public $ismultientitymanaged = 1;
79 public $isextrafieldmanaged = 1;
85 public $restrictiononfksoc = 1;
102 public $ref_supplier;
129 public $fk_user_author;
136 public $user_author_id;
141 public $user_creation;
146 public $user_cloture;
151 public $date_creation;
156 public $date_modification;
161 public $date_validation;
166 public $date_contrat;
168 public $commercial_signature_id;
169 public $commercial_suivi_id;
177 public $extraparams = array();
182 public $lines = array();
184 public $nbofservices;
185 public $nbofserviceswait;
186 public $nbofservicesopened;
187 public $nbofservicesexpired;
195 protected $lines_id_index_mapper = array();
226 public $fields = array(
227 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
228 'ref' =>array(
'type'=>
'varchar(50)',
'label'=>
'Ref',
'enabled'=>1,
'visible'=>-1,
'showoncombobox'=>1,
'position'=>15),
229 'ref_ext' =>array(
'type'=>
'varchar(255)',
'label'=>
'Ref ext',
'enabled'=>1,
'visible'=>0,
'position'=>20),
230 'ref_supplier' =>array(
'type'=>
'varchar(50)',
'label'=>
'Ref supplier',
'enabled'=>1,
'visible'=>-1,
'position'=>25),
231 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>30,
'index'=>1),
232 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>35),
233 'datec' =>array(
'type'=>
'datetime',
'label'=>
'DateCreation',
'enabled'=>1,
'visible'=>-1,
'position'=>40),
234 'date_contrat' =>array(
'type'=>
'datetime',
'label'=>
'Date contrat',
'enabled'=>1,
'visible'=>-1,
'position'=>45),
235 'fk_soc' =>array(
'type'=>
'integer:Societe:societe/class/societe.class.php',
'label'=>
'ThirdParty',
'enabled'=>
'$conf->societe->enabled',
'visible'=>-1,
'notnull'=>1,
'position'=>70),
236 'fk_projet' =>array(
'type'=>
'integer:Project:projet/class/project.class.php:1:(fk_statut:=:1)',
'label'=>
'Project',
'enabled'=>
"isModEnabled('project')",
'visible'=>-1,
'position'=>75),
237 'fk_commercial_signature' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'SaleRepresentative Signature',
'enabled'=>1,
'visible'=>-1,
'position'=>80),
238 'fk_commercial_suivi' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'SaleRepresentative follower',
'enabled'=>1,
'visible'=>-1,
'position'=>85),
239 'fk_user_author' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserAuthor',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>90),
240 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>105),
241 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>110),
242 'model_pdf' =>array(
'type'=>
'varchar(255)',
'label'=>
'Model pdf',
'enabled'=>1,
'visible'=>0,
'position'=>115),
243 'import_key' =>array(
'type'=>
'varchar(14)',
'label'=>
'ImportId',
'enabled'=>1,
'visible'=>-2,
'position'=>120),
244 'extraparams' =>array(
'type'=>
'varchar(255)',
'label'=>
'Extraparams',
'enabled'=>1,
'visible'=>-1,
'position'=>125),
245 'fk_user_modif' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserModif',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>135),
246 'last_main_doc' =>array(
'type'=>
'varchar(255)',
'label'=>
'Last main doc',
'enabled'=>1,
'visible'=>-1,
'position'=>140),
247 'statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Statut',
'enabled'=>1,
'visible'=>-1,
'position'=>500,
'notnull'=>1,
'arrayofkeyval'=>array(0=>
'Draft', 1=>
'Validated', 2=>
'Closed'))
251 const STATUS_DRAFT = 0;
252 const STATUS_VALIDATED = 1;
253 const STATUS_CLOSED = 2;
275 global $db, $langs, $conf;
276 $langs->load(
"contracts");
278 if (!empty($conf->global->CONTRACT_ADDON)) {
281 $file = $conf->global->CONTRACT_ADDON.
".php";
282 $classname = $conf->global->CONTRACT_ADDON;
285 $dirmodels = array_merge(array(
'/'), (array) $conf->modules_parts[
'models']);
287 foreach ($dirmodels as $reldir) {
291 $mybool |= @include_once $dir.$file;
299 $obj =
new $classname();
300 $numref = $obj->getNextValue($soc, $this);
305 $this->error = $obj->error;
310 $langs->load(
"errors");
311 print $langs->trans(
"Error").
" ".$langs->trans(
"ErrorModuleSetupNotComplete", $langs->transnoentitiesnoconv(
"Contract"));
327 public function active_line($user, $line_id, $date_start, $date_end =
'', $comment =
'')
330 $result = $this->lines[$this->lines_id_index_mapper[$line_id]]->active_line($user, $date_start, $date_end, $comment);
332 $this->error = $this->lines[$this->lines_id_index_mapper[$line_id]]->error;
333 $this->errors = $this->lines[$this->lines_id_index_mapper[$line_id]]->errors;
349 public function close_line($user, $line_id, $date_end, $comment =
'')
352 $result = $this->lines[$this->lines_id_index_mapper[$line_id]]->close_line($user, $date_end, $comment);
354 $this->error = $this->lines[$this->lines_id_index_mapper[$line_id]]->error;
355 $this->errors = $this->lines[$this->lines_id_index_mapper[$line_id]]->errors;
372 public function activateAll($user, $date_start =
'', $notrigger = 0, $comment =
'', $date_end =
'')
374 if (empty($date_start)) {
385 foreach ($this->lines as $contratline) {
387 if ($contratline->statut != ContratLigne::STATUS_OPEN) {
388 $contratline->context = $this->context;
390 $result = $contratline->active_line($user, $date_start, !empty($date_end) ? $date_end : -1, $comment);
393 $this->error = $contratline->error;
394 $this->errors = $contratline->errors;
400 if (!$error && $this->statut == 0) {
401 $result = $this->
validate($user,
'', $notrigger);
411 $this->
db->rollback();
436 foreach ($this->lines as $contratline) {
438 if ($contratline->statut != ContratLigne::STATUS_CLOSED) {
439 $contratline->date_end_real = $now;
440 $contratline->date_cloture = $now;
441 $contratline->fk_user_cloture = $user->id;
442 $contratline->statut = ContratLigne::STATUS_CLOSED;
443 $result = $contratline->close_line($user, $now, $comment, $notrigger);
446 $this->error = $contratline->error;
447 $this->errors = $contratline->errors;
453 if (!$error && $this->statut == 0) {
454 $result = $this->
validate($user,
'', $notrigger);
464 $this->
db->rollback();
477 public function validate(
User $user, $force_number =
'', $notrigger = 0)
479 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
480 global $langs, $conf;
485 dol_syslog(get_class($this).
'::validate user='.$user->id.
', force_number='.$force_number);
493 if (empty($conf->global->CONTRACT_DISABLE_AUTOSET_AS_CLIENT_ON_CONTRACT_VALIDATION)) {
494 $result = $this->thirdparty->set_as_client();
499 $num = $force_number;
500 } elseif (!$error && (preg_match(
'/^[\(]?PROV/i', $this->
ref) || empty($this->
ref))) {
508 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat SET ref = '".$this->
db->escape($num).
"', statut = 1";
510 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND statut = 0";
512 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
517 $this->error = $this->
db->lasterror();
521 if (!$error && !$notrigger) {
523 $result = $this->
call_trigger(
'CONTRACT_VALIDATE', $user);
531 $this->oldref = $this->ref;
534 if (preg_match(
'/^[\(]?PROV/i', $this->
ref)) {
536 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"ecm_files set filename = CONCAT('".$this->
db->escape($this->newref).
"', SUBSTR(filename, ".(strlen($this->
ref) + 1).
")), filepath = 'contract/".$this->
db->escape($this->newref).
"'";
537 $sql .=
" WHERE filename LIKE '".$this->db->escape($this->
ref).
"%' AND filepath = 'contract/".$this->
db->escape($this->
ref).
"' and entity = ".$conf->entity;
540 $error++; $this->error = $this->
db->lasterror();
546 $dirsource = $conf->contract->dir_output.
'/'.$oldref;
547 $dirdest = $conf->contract->dir_output.
'/'.$newref;
548 if (!$error && file_exists($dirsource)) {
549 dol_syslog(get_class($this).
"::validate rename dir ".$dirsource.
" into ".$dirdest);
551 if (@rename($dirsource, $dirdest)) {
554 $listoffiles =
dol_dir_list($conf->contract->dir_output.
'/'.$newref,
'files', 1,
'^'.preg_quote($oldref,
'/'));
555 foreach ($listoffiles as $fileentry) {
556 $dirsource = $fileentry[
'name'];
557 $dirdest = preg_replace(
'/^'.preg_quote($oldref,
'/').
'/', $newref, $dirsource);
558 $dirsource = $fileentry[
'path'].
'/'.$dirsource;
559 $dirdest = $fileentry[
'path'].
'/'.$dirdest;
560 @rename($dirsource, $dirdest);
571 $this->brouillon = 0;
572 $this->date_validation = $now;
582 $this->
db->rollback();
594 public function reopen($user, $notrigger = 0)
596 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
597 global $langs, $conf;
602 dol_syslog(get_class($this).
'::reopen user='.$user->id);
608 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat SET statut = 0";
610 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND statut = 1";
612 dol_syslog(get_class($this).
"::validate", LOG_DEBUG);
617 $this->error = $this->
db->lasterror();
621 if (!$error && !$notrigger) {
623 $result = $this->
call_trigger(
'CONTRACT_REOPEN', $user);
633 $this->brouillon = 1;
634 $this->date_validation = $now;
641 $this->
db->rollback();
655 public function fetch($id, $ref =
'', $ref_customer =
'', $ref_supplier =
'')
657 $sql =
"SELECT rowid, statut, ref, fk_soc,";
658 $sql .=
" ref_supplier, ref_customer,";
661 $sql .=
" date_contrat as datecontrat,";
662 $sql .=
" fk_user_author,";
663 $sql .=
" fk_projet as fk_project,";
664 $sql .=
" fk_commercial_signature, fk_commercial_suivi,";
665 $sql .=
" note_private, note_public, model_pdf, last_main_doc, extraparams";
666 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat";
668 $sql .=
" WHERE entity IN (".getEntity(
'contract').
")";
670 $sql .=
" WHERE rowid = ".(int) $id;
673 $sql .=
" AND ref_customer = '".$this->db->escape($ref_customer).
"'";
676 $sql .=
" AND ref_supplier = '".$this->db->escape($ref_supplier).
"'";
679 $sql .=
" AND ref = '".$this->db->escape($ref).
"'";
682 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
687 $this->error =
'Fetch found several records.';
691 $obj = $this->
db->fetch_object(
$resql);
693 $this->
id = $obj->rowid;
694 $this->
ref = (!isset($obj->ref) || !$obj->ref) ? $obj->rowid : $obj->ref;
695 $this->ref_customer = $obj->ref_customer;
696 $this->ref_supplier = $obj->ref_supplier;
697 $this->ref_ext = $obj->ref_ext;
698 $this->entity = $obj->entity;
699 $this->statut = $obj->statut;
701 $this->date_contrat = $this->db->jdate($obj->datecontrat);
702 $this->date_creation = $this->
db->jdate($obj->datecontrat);
704 $this->user_author_id = $obj->fk_user_author;
706 $this->commercial_signature_id = $obj->fk_commercial_signature;
707 $this->commercial_suivi_id = $obj->fk_commercial_suivi;
709 $this->note_private = $obj->note_private;
710 $this->note_public = $obj->note_public;
711 $this->model_pdf = $obj->model_pdf;
712 $this->modelpdf = $obj->model_pdf;
714 $this->fk_projet = $obj->fk_project;
715 $this->fk_project = $obj->fk_project;
717 $this->socid = $obj->fk_soc;
718 $this->fk_soc = $obj->fk_soc;
719 $this->last_main_doc = $obj->last_main_doc;
720 $this->extraparams = (isset($obj->extraparams) ? (array) json_decode($obj->extraparams,
true) :
null);
729 if ($result >= 0 && !empty($this->table_element_line)) {
734 $this->error = $this->
db->lasterror();
741 dol_syslog(get_class($this).
"::fetch Contract not found");
742 $this->error =
"Contract not found";
746 dol_syslog(get_class($this).
"::fetch Error searching contract");
747 $this->error = $this->
db->error();
761 public function fetch_lines($only_services = 0, $loadalsotranslation = 0)
764 global $langs, $conf;
766 $this->nbofservices = 0;
767 $this->nbofserviceswait = 0;
768 $this->nbofservicesopened = 0;
769 $this->nbofservicesexpired = 0;
770 $this->nbofservicesclosed = 0;
778 $this->lines = array();
782 $sql =
"SELECT p.label as product_label, p.description as product_desc, p.ref as product_ref, p.fk_product_type as product_type,";
783 $sql .=
" d.rowid, d.fk_contrat, d.statut, d.description, d.price_ht, d.vat_src_code, d.tva_tx, d.localtax1_tx, d.localtax2_tx, d.localtax1_type, d.localtax2_type, d.qty, d.remise_percent, d.subprice, d.fk_product_fournisseur_price as fk_fournprice, d.buy_price_ht as pa_ht,";
784 $sql .=
" d.total_ht,";
785 $sql .=
" d.total_tva,";
786 $sql .=
" d.total_localtax1,";
787 $sql .=
" d.total_localtax2,";
788 $sql .=
" d.total_ttc,";
789 $sql .=
" d.info_bits, d.fk_product,";
790 $sql .=
" d.date_ouverture_prevue as date_start,";
791 $sql .=
" d.date_ouverture as date_start_real,";
792 $sql .=
" d.date_fin_validite as date_end,";
793 $sql .=
" d.date_cloture as date_end_real,";
794 $sql .=
" d.fk_user_author,";
795 $sql .=
" d.fk_user_ouverture,";
796 $sql .=
" d.fk_user_cloture,";
797 $sql .=
" d.fk_unit,";
798 $sql .=
" d.product_type as type,";
800 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as d LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON d.fk_product = p.rowid";
801 $sql .=
" WHERE d.fk_contrat = ".((int) $this->
id);
802 if ($only_services == 1) {
803 $sql .=
" AND d.product_type = 1";
805 $sql .=
" ORDER by d.rang ASC";
807 dol_syslog(get_class($this).
"::fetch_lines", LOG_DEBUG);
808 $result = $this->
db->query($sql);
810 $num = $this->
db->num_rows($result);
814 $objp = $this->
db->fetch_object($result);
818 $line->id = $objp->rowid;
819 $line->ref = $objp->rowid;
820 $line->fk_contrat = $objp->fk_contrat;
821 $line->desc = $objp->description;
822 $line->qty = $objp->qty;
823 $line->vat_src_code = $objp->vat_src_code;
824 $line->tva_tx = $objp->tva_tx;
825 $line->localtax1_tx = $objp->localtax1_tx;
826 $line->localtax2_tx = $objp->localtax2_tx;
827 $line->localtax1_type = $objp->localtax1_type;
828 $line->localtax2_type = $objp->localtax2_type;
829 $line->subprice = $objp->subprice;
830 $line->statut = $objp->statut;
831 $line->remise_percent = $objp->remise_percent;
832 $line->price_ht = $objp->price_ht;
833 $line->price = $objp->price_ht;
834 $line->total_ht = $objp->total_ht;
835 $line->total_tva = $objp->total_tva;
836 $line->total_localtax1 = $objp->total_localtax1;
837 $line->total_localtax2 = $objp->total_localtax2;
838 $line->total_ttc = $objp->total_ttc;
839 $line->fk_product = (($objp->fk_product > 0) ? $objp->fk_product : 0);
840 $line->info_bits = $objp->info_bits;
841 $line->type = $objp->type;
843 $line->fk_fournprice = $objp->fk_fournprice;
844 $marginInfos =
getMarginInfos($objp->subprice, $objp->remise_percent, $objp->tva_tx, $objp->localtax1_tx, $objp->localtax2_tx, $objp->fk_fournprice, $objp->pa_ht);
845 $line->pa_ht = $marginInfos[0];
847 $line->fk_user_author = $objp->fk_user_author;
848 $line->fk_user_ouverture = $objp->fk_user_ouverture;
849 $line->fk_user_cloture = $objp->fk_user_cloture;
850 $line->fk_unit = $objp->fk_unit;
852 $line->ref = $objp->product_ref;
853 $line->product_ref = $objp->product_ref;
854 $line->product_type = $objp->product_type;
855 $line->product_desc = $objp->product_desc;
856 $line->product_label = $objp->product_label;
858 $line->description = $objp->description;
860 $line->date_start = $this->
db->jdate($objp->date_start);
861 $line->date_start_real = $this->
db->jdate($objp->date_start_real);
862 $line->date_end = $this->
db->jdate($objp->date_end);
863 $line->date_end_real = $this->
db->jdate($objp->date_end_real);
874 $line->rang = $objp->rang;
878 $line->fetch_optionals();
881 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && !empty($objp->fk_product) && !empty($loadalsotranslation)) {
883 $tmpproduct->fetch($objp->fk_product);
884 $tmpproduct->getMultiLangs();
886 $line->multilangs = $tmpproduct->multilangs;
889 $this->lines[$pos] = $line;
891 $this->lines_id_index_mapper[$line->id] = $pos;
896 if ($line->statut == ContratLigne::STATUS_INITIAL) {
897 $this->nbofserviceswait++;
899 if ($line->statut == ContratLigne::STATUS_OPEN && (empty($line->date_end) || $line->date_end >= $now)) {
900 $this->nbofservicesopened++;
902 if ($line->statut == ContratLigne::STATUS_OPEN && (!empty($line->date_end) && $line->date_end < $now)) {
903 $this->nbofservicesexpired++;
905 if ($line->statut == ContratLigne::STATUS_CLOSED) {
906 $this->nbofservicesclosed++;
909 $total_ttc += $objp->total_ttc;
910 $total_vat += $objp->total_tva;
911 $total_ht += $objp->total_ht;
916 $this->
db->free($result);
918 dol_syslog(get_class($this).
"::Fetch Error when reading lines of contracts linked to products");
923 $this->nbofservices = count($this->lines);
924 $this->total_ttc =
price2num($total_ttc);
925 $this->total_tva =
price2num($total_vat);
939 global $conf, $langs, $mysoc;
943 if ($this->commercial_signature_id <= 0) {
944 $langs->load(
"commercial");
945 $this->error .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"SalesRepresentativeSignature"));
948 if ($this->commercial_suivi_id <= 0) {
949 $langs->load(
"commercial");
950 $this->error .= ($this->error ?
"<br>" :
'');
951 $this->error .= $langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"SalesRepresentativeFollowUp"));
964 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contrat (datec, fk_soc, fk_user_author, date_contrat,";
965 $sql .=
" fk_commercial_signature, fk_commercial_suivi, fk_projet,";
966 $sql .=
" ref, entity, note_private, note_public, ref_customer, ref_supplier, ref_ext)";
967 $sql .=
" VALUES ('".$this->db->idate($now).
"', ".((int) $this->socid).
", ".((int) $user->id);
968 $sql .=
", ".(dol_strlen($this->date_contrat) != 0 ?
"'".$this->db->idate($this->date_contrat).
"'" :
"NULL");
969 $sql .=
",".($this->commercial_signature_id > 0 ? ((int) $this->commercial_signature_id) :
"NULL");
970 $sql .=
",".($this->commercial_suivi_id > 0 ? ((int) $this->commercial_suivi_id) :
"NULL");
971 $sql .=
",".($this->fk_project > 0 ? ((int) $this->fk_project) :
"NULL");
972 $sql .=
", ".(dol_strlen($this->
ref) <= 0 ?
"null" :
"'".$this->db->escape($this->
ref).
"'");
973 $sql .=
", ".((int) $conf->entity);
974 $sql .=
", ".(!empty($this->note_private) ? (
"'".$this->db->escape($this->note_private).
"'") :
"NULL");
975 $sql .=
", ".(!empty($this->note_public) ? (
"'".$this->db->escape($this->note_public).
"'") :
"NULL");
976 $sql .=
", ".(!empty($this->ref_customer) ? (
"'".$this->db->escape($this->ref_customer).
"'") :
"NULL");
977 $sql .=
", ".(!empty($this->ref_supplier) ? (
"'".$this->db->escape($this->ref_supplier).
"'") :
"NULL");
978 $sql .=
", ".(!empty($this->ref_ext) ? (
"'".$this->db->escape($this->ref_ext).
"'") :
"NULL");
985 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"contrat");
988 $module = (!empty($conf->global->CONTRACT_ADDON) ? $conf->global->CONTRACT_ADDON :
'mod_contract_serpis');
989 if (substr($module, 0, 13) ==
'mod_contract_' && substr($module, -3) ==
'php') {
990 $module = substr($module, 0,
dol_strlen($module) - 4);
994 $modCodeContract =
new $module();
996 if (!empty($modCodeContract->code_auto)) {
998 $sql =
'UPDATE '.MAIN_DB_PREFIX.
"contrat SET ref='(PROV".$this->
id.
")' WHERE rowid=".((int) $this->
id);
999 if ($this->
db->query($sql)) {
1001 $this->
ref =
"(PROV".$this->id.
")";
1016 $result = $this->
add_contact($this->commercial_signature_id,
'SALESREPSIGN',
'internal');
1024 $result = $this->
add_contact($this->commercial_suivi_id,
'SALESREPFOLL',
'internal');
1031 if (!empty($this->linkedObjectsIds) && empty($this->linked_objects)) {
1032 $this->linked_objects = $this->linkedObjectsIds;
1036 if (!$error && $this->
id && !empty($this->linked_objects) && is_array($this->linked_objects)) {
1037 foreach ($this->linked_objects as $origin => $tmp_origin_id) {
1038 if (is_array($tmp_origin_id)) {
1039 foreach ($tmp_origin_id as $origin_id) {
1042 $this->error = $this->
db->lasterror();
1048 $origin_id = $tmp_origin_id;
1051 $this->error = $this->
db->lasterror();
1058 if (!$error && $this->
id && !empty($conf->global->MAIN_PROPAGATE_CONTACTS_FROM_ORIGIN) && !empty($this->origin) && !empty($this->origin_id)) {
1059 $originforcontact = $this->origin;
1060 $originidforcontact = $this->origin_id;
1061 if ($originforcontact ==
'shipping') {
1062 require_once DOL_DOCUMENT_ROOT.
'/expedition/class/expedition.class.php';
1064 $exp->fetch($this->origin_id);
1065 $exp->fetchObjectLinked();
1066 if (count($exp->linkedObjectsIds[
'commande']) > 0) {
1067 foreach ($exp->linkedObjectsIds[
'commande'] as $key => $value) {
1068 $originforcontact =
'commande';
1069 $originidforcontact = $value;
1075 $sqlcontact =
"SELECT ctc.code, ctc.source, ec.fk_socpeople FROM ".MAIN_DB_PREFIX.
"element_contact as ec, ".MAIN_DB_PREFIX.
"c_type_contact as ctc";
1076 $sqlcontact .=
" WHERE element_id = ".((int) $originidforcontact).
" AND ec.fk_c_type_contact = ctc.rowid AND ctc.element = '".$this->
db->escape($originforcontact).
"'";
1078 $resqlcontact = $this->
db->query($sqlcontact);
1079 if ($resqlcontact) {
1080 while ($objcontact = $this->
db->fetch_object($resqlcontact)) {
1081 if ($objcontact->source ==
'internal' && in_array($objcontact->code, array(
'SALESREPSIGN',
'SALESREPFOLL'))) {
1086 $this->
add_contact($objcontact->fk_socpeople, $objcontact->code, $objcontact->source);
1096 $result = $this->
call_trigger(
'CONTRACT_CREATE', $user);
1103 $this->
db->commit();
1106 dol_syslog(get_class($this).
"::create - 30 - ".$this->error, LOG_ERR);
1107 $this->
db->rollback();
1111 $this->error =
"Failed to add contract";
1112 dol_syslog(get_class($this).
"::create - 20 - ".$this->error, LOG_ERR);
1113 $this->
db->rollback();
1117 $this->error = $langs->trans(
"UnknownError: ".$this->
db->error().
" -", LOG_DEBUG);
1119 $this->
db->rollback();
1131 public function delete($user)
1133 global $conf, $langs;
1134 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1141 $result = $this->
call_trigger(
'CONTRACT_DELETE', $user);
1151 dol_syslog(get_class($this).
"::delete error", LOG_ERR);
1171 $sql =
"SELECT cdl.rowid as cdlrowid ";
1172 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet_log as cdl, ".MAIN_DB_PREFIX.
"contratdet as cd";
1173 $sql .=
" WHERE cdl.fk_contratdet=cd.rowid AND cd.fk_contrat=".((int) $this->
id);
1175 dol_syslog(get_class($this).
"::delete contratdet_log", LOG_DEBUG);
1178 $this->error = $this->
db->error();
1181 $numressql = $this->
db->num_rows(
$resql);
1182 if (!$error && $numressql) {
1183 $tab_resql = array();
1184 for ($i = 0; $i < $numressql; $i++) {
1185 $objresql = $this->
db->fetch_object(
$resql);
1186 $tab_resql[] = $objresql->cdlrowid;
1190 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"contratdet_log ";
1191 $sql .=
" WHERE ".MAIN_DB_PREFIX.
"contratdet_log.rowid IN (".$this->
db->sanitize(implode(
",", $tab_resql)).
")";
1193 dol_syslog(get_class($this).
"::delete contratdet_log", LOG_DEBUG);
1196 $this->error = $this->
db->error();
1205 $main = MAIN_DB_PREFIX.
'contratdet';
1206 $ef = $main.
"_extrafields";
1207 $sql =
"DELETE FROM ".$ef.
" WHERE fk_object IN (SELECT rowid FROM ".$main.
" WHERE fk_contrat = ".((int) $this->
id).
")";
1209 dol_syslog(get_class($this).
"::delete contratdet_extrafields", LOG_DEBUG);
1212 $this->error = $this->
db->error();
1219 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"contratdet";
1220 $sql .=
" WHERE fk_contrat=".((int) $this->
id);
1222 dol_syslog(get_class($this).
"::delete contratdet", LOG_DEBUG);
1225 $this->error = $this->
db->error();
1232 $sql =
'DELETE FROM '.MAIN_DB_PREFIX.
"ecm_files WHERE src_object_type = '".$this->
db->escape($this->table_element.(empty($this->module) ?
"" :
"@".$this->module)).
"' AND src_object_id = ".((
int) $this->id);
1235 $this->error = $this->
db->lasterror();
1236 $this->errors[] = $this->error;
1243 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.
"contrat";
1244 $sql .=
" WHERE rowid=".((int) $this->
id);
1246 dol_syslog(get_class($this).
"::delete contrat", LOG_DEBUG);
1249 $this->error = $this->
db->error();
1259 dol_syslog(get_class($this).
"::delete error -3 ".$this->error, LOG_ERR);
1266 if ($conf->contrat->dir_output) {
1267 $dir = $conf->contrat->multidir_output[$this->entity].
"/".$ref;
1268 if (file_exists($dir)) {
1271 $this->error =
'ErrorFailToDeleteDir';
1279 $this->
db->commit();
1282 $this->error = $this->
db->lasterror();
1283 $this->
db->rollback();
1295 public function update($user, $notrigger = 0)
1297 global $conf, $langs;
1301 if (empty($this->fk_commercial_signature) && $this->commercial_signature_id > 0) {
1302 $this->fk_commercial_signature = $this->commercial_signature_id;
1304 if (empty($this->fk_commercial_suivi) && $this->commercial_suivi_id > 0) {
1305 $this->fk_commercial_suivi = $this->commercial_suivi_id;
1307 if (empty($this->fk_soc) && $this->socid > 0) {
1308 $this->fk_soc = (int) $this->socid;
1310 if (empty($this->fk_project) && $this->projet > 0) {
1311 $this->fk_project = (int) $this->projet;
1314 if (isset($this->
ref)) {
1315 $this->
ref = trim($this->
ref);
1317 if (isset($this->ref_customer)) {
1318 $this->ref_customer = trim($this->ref_customer);
1320 if (isset($this->ref_supplier)) {
1321 $this->ref_supplier = trim($this->ref_supplier);
1323 if (isset($this->ref_ext)) {
1324 $this->ref_ext = trim($this->ref_ext);
1326 if (isset($this->entity)) {
1327 $this->entity = (int) $this->entity;
1329 if (isset($this->statut)) {
1330 $this->statut = (int) $this->statut;
1332 if (isset($this->fk_soc)) {
1333 $this->fk_soc = (int) $this->fk_soc;
1335 if (isset($this->fk_commercial_signature)) {
1336 $this->fk_commercial_signature = trim($this->fk_commercial_signature);
1338 if (isset($this->fk_commercial_suivi)) {
1339 $this->fk_commercial_suivi = trim($this->fk_commercial_suivi);
1341 if (isset($this->note_private)) {
1342 $this->note_private = trim($this->note_private);
1344 if (isset($this->note_public)) {
1345 $this->note_public = trim($this->note_public);
1347 if (isset($this->import_key)) {
1348 $this->import_key = trim($this->import_key);
1356 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contrat SET";
1357 $sql .=
" ref=".(isset($this->
ref) ?
"'".$this->db->escape($this->
ref).
"'" :
"null").
",";
1358 $sql .=
" ref_customer=".(isset($this->ref_customer) ?
"'".$this->db->escape($this->ref_customer).
"'" :
"null").
",";
1359 $sql .=
" ref_supplier=".(isset($this->ref_supplier) ?
"'".$this->db->escape($this->ref_supplier).
"'" :
"null").
",";
1360 $sql .=
" ref_ext=".(isset($this->ref_ext) ?
"'".$this->db->escape($this->ref_ext).
"'" :
"null").
",";
1361 $sql .=
" entity=".$conf->entity.
",";
1362 $sql .=
" date_contrat=".(dol_strlen($this->date_contrat) != 0 ?
"'".$this->db->idate($this->date_contrat).
"'" :
'null').
",";
1363 $sql .=
" statut=".(isset($this->statut) ? $this->statut :
"null").
",";
1364 $sql .=
" fk_soc=".($this->fk_soc > 0 ? $this->fk_soc :
"null").
",";
1365 $sql .=
" fk_projet=".($this->fk_project > 0 ? $this->fk_project :
"null").
",";
1366 $sql .=
" fk_commercial_signature=".(isset($this->fk_commercial_signature) ? $this->fk_commercial_signature :
"null").
",";
1367 $sql .=
" fk_commercial_suivi=".(isset($this->fk_commercial_suivi) ? $this->fk_commercial_suivi :
"null").
",";
1368 $sql .=
" note_private=".(isset($this->note_private) ?
"'".$this->db->escape($this->note_private).
"'" :
"null").
",";
1369 $sql .=
" note_public=".(isset($this->note_public) ?
"'".$this->db->escape($this->note_public).
"'" :
"null").
",";
1370 $sql .=
" import_key=".(isset($this->import_key) ?
"'".$this->db->escape($this->import_key).
"'" :
"null").
"";
1372 $sql .=
" WHERE rowid=".((int) $this->
id);
1378 $error++; $this->errors[] =
"Error ".$this->db->lasterror();
1388 if (!$error && !$notrigger) {
1390 $result = $this->
call_trigger(
'CONTRACT_MODIFY', $user);
1399 foreach ($this->errors as $errmsg) {
1400 dol_syslog(get_class($this).
"::update ".$errmsg, LOG_ERR);
1401 $this->error .= ($this->error ?
', '.$errmsg : $errmsg);
1403 $this->
db->rollback();
1406 $this->
db->commit();
1435 public function addline($desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type =
'HT', $pu_ttc = 0.0, $info_bits = 0, $fk_fournprice =
null, $pa_ht = 0, $array_options = 0, $fk_unit =
null, $rang = 0)
1437 global $user, $langs, $conf, $mysoc;
1440 dol_syslog(get_class($this).
"::addline $desc, $pu_ht, $qty, $txtva, $txlocaltax1, $txlocaltax2, $fk_product, $remise_percent, $date_start, $date_end, $price_base_type, $pu_ttc, $info_bits, $rang");
1443 if ($fk_product <= 0 && empty($desc)) {
1444 $this->error =
"ErrorDescRequiredForFreeProductLines";
1448 if ($this->statut >= 0) {
1457 if (preg_match(
'/\((.*)\)/', $txtva, $reg)) {
1458 $vat_src_code = $reg[1];
1459 $txtva = preg_replace(
'/\s*\(.*\)/',
'', $txtva);
1465 $remise_percent =
price2num($remise_percent);
1470 if (empty($info_bits)) {
1473 if (empty($pu_ht) || !is_numeric($pu_ht)) {
1476 if (empty($pu_ttc)) {
1479 if (empty($txtva) || !is_numeric($txtva)) {
1482 if (empty($txlocaltax1) || !is_numeric($txlocaltax1)) {
1485 if (empty($txlocaltax2) || !is_numeric($txlocaltax2)) {
1489 if ($price_base_type ==
'HT') {
1496 if (empty($remise_percent)) {
1497 $remise_percent = 0;
1503 if ($date_start && $date_end && $date_start > $date_end) {
1504 $langs->load(
"errors");
1505 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1511 $localtaxes_type =
getLocalTaxesFromRate($txtva.($vat_src_code ?
' ('.$vat_src_code.
')' :
''), 0, $this->societe, $mysoc);
1518 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $txtva, $txlocaltax1, $txlocaltax2, 0, $price_base_type, $info_bits, 1, $mysoc, $localtaxes_type);
1519 $total_ht = $tabprice[0];
1520 $total_tva = $tabprice[1];
1521 $total_ttc = $tabprice[2];
1522 $total_localtax1 = $tabprice[9];
1523 $total_localtax2 = $tabprice[10];
1525 $localtax1_type = $localtaxes_type[0];
1526 $localtax2_type = $localtaxes_type[2];
1533 $remise = round(($pu_ht * $remise_percent / 100), 2);
1534 $price = $pu_ht - $remise;
1537 if (empty($pa_ht)) {
1543 if ($this->pa_ht == 0) {
1544 if (($result = $this->
defineBuyPrice($pu_ht, $remise_percent, $fk_product)) < 0) {
1552 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet";
1553 $sql .=
" (fk_contrat, label, description, fk_product, qty, tva_tx, vat_src_code,";
1554 $sql .=
" localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice,";
1555 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc,";
1556 $sql .=
" info_bits,";
1557 $sql .=
" price_ht, remise, fk_product_fournisseur_price, buy_price_ht";
1558 if ($date_start > 0) {
1559 $sql .=
",date_ouverture_prevue";
1561 if ($date_end > 0) {
1562 $sql .=
",date_fin_validite";
1564 $sql .=
", fk_unit";
1566 $sql .=
") VALUES (";
1567 $sql .= $this->
id.
", '', '".$this->
db->escape($desc).
"',";
1568 $sql .= ($fk_product > 0 ? $fk_product :
"null").
",";
1569 $sql .=
" ".((float) $qty).
",";
1570 $sql .=
" ".((float) $txtva).
",";
1571 $sql .=
" ".($vat_src_code ?
"'".$this->db->escape($vat_src_code).
"'" :
"null").
",";
1572 $sql .=
" ".((float) $txlocaltax1).
",";
1573 $sql .=
" ".((float) $txlocaltax2).
",";
1574 $sql .=
" '".$this->db->escape($localtax1_type).
"',";
1575 $sql .=
" '".$this->db->escape($localtax2_type).
"',";
1576 $sql .=
" ".price2num($remise_percent).
",";
1577 $sql .=
" ".price2num($pu_ht).
",";
1579 $sql .=
" '".$this->db->escape($info_bits).
"',";
1580 $sql .=
" ".price2num($price).
",".
price2num($remise).
",";
1581 if (isset($fk_fournprice)) {
1582 $sql .=
' '.((int) $fk_fournprice).
',';
1586 if (isset($pa_ht)) {
1587 $sql .=
' '.price2num($pa_ht);
1591 if ($date_start > 0) {
1592 $sql .=
",'".$this->db->idate($date_start).
"'";
1594 if ($date_end > 0) {
1595 $sql .=
",'".$this->db->idate($date_end).
"'";
1597 $sql .=
", ".($fk_unit ?
"'".$this->db->escape($fk_unit).
"'" :
"null");
1598 $sql .=
", ".(!empty($rang) ? (int) $rang :
"0");
1603 $contractlineid = $this->
db->last_insert_id(MAIN_DB_PREFIX.
"contratdet");
1607 $contractline->array_options = $array_options;
1608 $contractline->id = $contractlineid;
1609 $result = $contractline->insertExtraFields();
1611 $this->error[] = $contractline->error;
1616 if (empty($error)) {
1618 $result = $this->
call_trigger(
'LINECONTRACT_INSERT', $user);
1626 $this->
db->rollback();
1629 $this->
db->commit();
1630 return $contractlineid;
1633 $this->
db->rollback();
1634 $this->error = $this->
db->error().
" sql=".$sql;
1638 dol_syslog(get_class($this).
"::addline ErrorTryToAddLineOnValidatedContract", LOG_ERR);
1667 public function updateline($rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $tvatx, $localtax1tx = 0.0, $localtax2tx = 0.0, $date_start_real =
'', $date_end_real =
'', $price_base_type =
'HT', $info_bits = 0, $fk_fournprice =
null, $pa_ht = 0, $array_options = 0, $fk_unit =
null, $rang = 0)
1669 global $user, $conf, $langs, $mysoc;
1675 $desc = trim($desc);
1676 $desc = trim($desc);
1682 if (empty($fk_fournprice)) {
1692 $remise = round(($pu * $remise_percent / 100), 2);
1693 $price = $pu - $remise;
1695 $remise_percent = 0;
1698 if ($date_start && $date_end && $date_start > $date_end) {
1699 $langs->load(
"errors");
1700 $this->error = $langs->trans(
'ErrorStartDateGreaterEnd');
1704 dol_syslog(get_class($this).
"::updateline $rowid, $desc, $pu, $qty, $remise_percent, $date_start, $date_end, $date_start_real, $date_end_real, $tvatx, $localtax1tx, $localtax2tx, $price_base_type, $info_bits, $rang");
1714 $tvatx = preg_replace(
'/\s*\(.*\)/',
'', $tvatx);
1716 $tabprice =
calcul_price_total($qty, $pu, $remise_percent, $tvatx, $localtax1tx, $localtax2tx, 0, $price_base_type, $info_bits, 1, $mysoc, $localtaxes_type);
1717 $total_ht = $tabprice[0];
1718 $total_tva = $tabprice[1];
1719 $total_ttc = $tabprice[2];
1720 $total_localtax1 = $tabprice[9];
1721 $total_localtax2 = $tabprice[10];
1723 $localtax1_type = (empty($localtaxes_type[0]) ?
'' : $localtaxes_type[0]);
1724 $localtax2_type = (empty($localtaxes_type[2]) ?
'' : $localtaxes_type[2]);
1731 $remise = round(($pu * $remise_percent / 100), 2);
1732 $price = $pu - $remise;
1735 if (empty($pa_ht)) {
1740 if ($this->pa_ht == 0) {
1741 if (($result = $this->
defineBuyPrice($pu, $remise_percent)) < 0) {
1748 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contratdet set description = '".$this->
db->escape($desc).
"'";
1749 $sql .=
",price_ht = ".((float)
price2num($price));
1750 $sql .=
",subprice = ".((float)
price2num($subprice));
1751 $sql .=
",remise = ".((float)
price2num($remise));
1752 $sql .=
",remise_percent = ".((float)
price2num($remise_percent));
1753 $sql .=
",qty = ".((float) $qty);
1754 $sql .=
",tva_tx = ".((float)
price2num($tvatx));
1755 $sql .=
",localtax1_tx = ".((float)
price2num($localtax1tx));
1756 $sql .=
",localtax2_tx = ".((float)
price2num($localtax2tx));
1757 $sql .=
",localtax1_type='".$this->db->escape($localtax1_type).
"'";
1758 $sql .=
",localtax2_type='".$this->db->escape($localtax2_type).
"'";
1759 $sql .=
", total_ht = ".((float)
price2num($total_ht));
1760 $sql .=
", total_tva = ".((float)
price2num($total_tva));
1761 $sql .=
", total_localtax1 = ".((float)
price2num($total_localtax1));
1762 $sql .=
", total_localtax2 = ".((float)
price2num($total_localtax2));
1763 $sql .=
", total_ttc = ".((float)
price2num($total_ttc));
1764 $sql .=
", fk_product_fournisseur_price=".($fk_fournprice > 0 ? $fk_fournprice :
"null");
1765 $sql .=
", buy_price_ht = ".((float)
price2num($pa_ht));
1766 if ($date_start > 0) {
1767 $sql .=
",date_ouverture_prevue = '".$this->db->idate($date_start).
"'";
1769 $sql .=
",date_ouverture_prevue = null";
1771 if ($date_end > 0) {
1772 $sql .=
",date_fin_validite = '".$this->db->idate($date_end).
"'";
1774 $sql .=
",date_fin_validite = null";
1776 if ($date_start_real > 0) {
1777 $sql .=
",date_ouverture = '".$this->db->idate($date_start_real).
"'";
1779 $sql .=
",date_ouverture = null";
1781 if ($date_end_real > 0) {
1782 $sql .=
",date_cloture = '".$this->db->idate($date_end_real).
"'";
1784 $sql .=
",date_cloture = null";
1786 $sql .=
", fk_unit = ".($fk_unit > 0 ? ((int) $fk_unit) :
"null");
1787 $sql .=
", rang = ".(!empty($rang) ? ((int) $rang) :
"0");
1788 $sql .=
" WHERE rowid = ".((int) $rowid);
1790 dol_syslog(get_class($this).
"::updateline", LOG_DEBUG);
1791 $result = $this->
db->query($sql);
1793 if (is_array($array_options) && count($array_options) > 0) {
1795 $contractline->fetch($rowid);
1798 foreach ($array_options as $key => $value) {
1799 $contractline->array_options[$key] = $array_options[$key];
1802 $result = $contractline->insertExtraFields();
1804 $this->error[] = $contractline->error;
1809 if (empty($error)) {
1811 $result = $this->
call_trigger(
'LINECONTRACT_MODIFY', $user);
1813 $this->
db->rollback();
1818 $this->
db->commit();
1822 $this->
db->rollback();
1823 $this->error = $this->
db->error();
1824 dol_syslog(get_class($this).
"::updateline Erreur -1");
1838 global $conf, $langs;
1842 if ($this->statut >= 0) {
1844 $result = $this->
call_trigger(
'LINECONTRACT_DELETE', $user);
1852 $sql =
"DELETE FROM ".MAIN_DB_PREFIX.$this->table_element_line;
1853 $sql .=
" WHERE rowid = ".((int) $idline);
1855 dol_syslog(get_class($this).
"::deleteline", LOG_DEBUG);
1858 $this->error =
"Error ".$this->db->lasterror();
1865 $contractline->id = $idline;
1866 $result = $contractline->deleteExtraFields();
1869 $this->error =
"Error ".get_class($this).
"::deleteline deleteExtraFields error -4 ".$contractline->error;
1873 if (empty($error)) {
1874 $this->
db->commit();
1877 dol_syslog(get_class($this).
"::deleteline ERROR:".$this->error, LOG_ERR);
1878 $this->
db->rollback();
1882 $this->error =
'ErrorDeleteLineNotAllowedByObjectStatus';
1899 dol_syslog(__METHOD__.
" is deprecated", LOG_WARNING);
1902 if ($this->statut == 0) {
1927 return $this->
LibStatut($this->statut, $mode);
1943 if (empty($this->labelStatus) || empty($this->labelStatusShort)) {
1945 $langs->load(
"contracts");
1946 $this->labelStatus[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'ContractStatusDraft');
1947 $this->labelStatus[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'ContractStatusValidated');
1948 $this->labelStatus[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'ContractStatusClosed');
1949 $this->labelStatusShort[self::STATUS_DRAFT] = $langs->transnoentitiesnoconv(
'ContractStatusDraft');
1950 $this->labelStatusShort[self::STATUS_VALIDATED] = $langs->transnoentitiesnoconv(
'ContractStatusValidated');
1951 $this->labelStatusShort[self::STATUS_CLOSED] = $langs->transnoentitiesnoconv(
'ContractStatusClosed');
1954 $statusType =
'status'.$status;
1955 if ($status == self::STATUS_VALIDATED) {
1956 $statusType =
'status6';
1959 if ($mode == 4 || $mode == 6 || $mode == 7) {
1962 $text =
'<span class="hideonsmartphone">';
1963 $text .= ($this->nbofserviceswait + $this->nbofservicesopened + $this->nbofservicesexpired + $this->nbofservicesclosed);
1964 $text .=
' '.$langs->trans(
"Services");
1965 $text .=
': ';
1968 $text .= ($mode == 7 ?
'<span class="nowraponall">' :
'');
1969 $text .= ($mode != 7 || $this->nbofserviceswait > 0) ? ($this->nbofserviceswait.ContratLigne::LibStatut(0, 3, -1,
'class="marginleft2"')).(($mode != 7 || $this->nbofservicesopened || $this->nbofservicesexpired || $this->nbofservicesclosed) ?
' ' :
'') :
'';
1970 $text .= ($mode == 7 ?
'</span><span class="nowraponall">' :
'');
1971 $text .= ($mode != 7 || $this->nbofservicesopened > 0) ? ($this->nbofservicesopened.ContratLigne::LibStatut(4, 3, 0,
'class="marginleft2"')).(($mode != 7 || $this->nbofservicesexpired || $this->nbofservicesclosed) ?
' ' :
'') :
'';
1972 $text .= ($mode == 7 ?
'</span><span class="nowraponall">' :
'');
1973 $text .= ($mode != 7 || $this->nbofservicesexpired > 0) ? ($this->nbofservicesexpired.ContratLigne::LibStatut(4, 3, 1,
'class="marginleft2"')).(($mode != 7 || $this->nbofservicesclosed) ?
' ' :
'') :
'';
1974 $text .= ($mode == 7 ?
'</span><span class="nowraponall">' :
'');
1975 $text .= ($mode != 7 || $this->nbofservicesclosed > 0) ? ($this->nbofservicesclosed.ContratLigne::LibStatut(5, 3, -1,
'class="marginleft2"')) :
'';
1976 $text .= ($mode == 7 ?
'</span>' :
'');
1979 return dolGetStatus($this->labelStatus[$status], $this->labelStatusShort[$status],
'', $statusType, $mode);
1993 public function getNomUrl($withpicto = 0, $maxlength = 0, $notooltip = 0, $save_lastsearch_value = -1)
1995 global $conf, $langs, $user, $hookmanager;
1999 $url = DOL_URL_ROOT.
'/contrat/card.php?id='.$this->id;
2004 $add_save_lastsearch_values = ($save_lastsearch_value == 1 ? 1 : 0);
2005 if ($save_lastsearch_value == -1 && preg_match(
'/list\.php/', $_SERVER[
"PHP_SELF"])) {
2006 $add_save_lastsearch_values = 1;
2008 if ($add_save_lastsearch_values) {
2009 $url .=
'&save_lastsearch_values=1';
2015 if ($user->rights->contrat->lire) {
2016 $label =
img_picto(
'', $this->picto).
' <u class="paddingrightonly">'.$langs->trans(
"Contract").
'</u>';
2021 $label .=
'<br><b>'.$langs->trans(
'Ref').
':</b> '.($this->
ref ? $this->
ref : $this->id);
2022 $ref_customer = (!empty($this->ref_customer) ? $this->ref_customer : (empty($this->ref_client) ?
'' : $this->ref_client));
2023 $label .=
'<br><b>'.$langs->trans(
'RefCustomer').
':</b> '.$ref_customer;
2024 $label .=
'<br><b>'.$langs->trans(
'RefSupplier').
':</b> '.$this->ref_supplier;
2025 if (!empty($this->total_ht)) {
2026 $label .=
'<br><b>'.$langs->trans(
'AmountHT').
':</b> '.
price($this->total_ht, 0, $langs, 0, -1, -1, $conf->currency);
2028 if (!empty($this->total_tva)) {
2029 $label .=
'<br><b>'.$langs->trans(
'VAT').
':</b> '.
price($this->total_tva, 0, $langs, 0, -1, -1, $conf->currency);
2031 if (!empty($this->total_ttc)) {
2032 $label .=
'<br><b>'.$langs->trans(
'AmountTTC').
':</b> '.
price($this->total_ttc, 0, $langs, 0, -1, -1, $conf->currency);
2037 if (empty($notooltip) && $user->rights->contrat->lire) {
2038 if (!empty($conf->global->MAIN_OPTIMIZEFORTEXTBROWSER)) {
2039 $label = $langs->trans(
"ShowOrder");
2040 $linkclose .=
' alt="'.dol_escape_htmltag($label, 1).
'"';
2042 $linkclose .=
' title="'.dol_escape_htmltag($label, 1).
'"';
2043 $linkclose .=
' class="classfortooltip"';
2046 $linkstart =
'<a href="'.$url.
'"';
2047 $linkstart .= $linkclose.
'>';
2050 $result .= $linkstart;
2052 $result .=
img_object(($notooltip ?
'' : $label), $this->picto, ($notooltip ? (($withpicto != 2) ?
'class="paddingright"' :
'') :
'class="'.(($withpicto != 2) ?
'paddingright ' :
'').
'classfortooltip"'), 0, 0, $notooltip ? 0 : 1);
2054 if ($withpicto != 2) {
2055 $result .= ($this->
ref ? $this->
ref : $this->id);
2057 $result .= $linkend;
2060 $hookmanager->initHooks(array(
'contractdao'));
2061 $parameters = array(
'id'=>$this->
id,
'getnomurl' => &$result);
2062 $reshook = $hookmanager->executeHooks(
'getNomUrl', $parameters, $this, $action);
2064 $result = $hookmanager->resPrint;
2066 $result .= $hookmanager->resPrint;
2080 $sql =
"SELECT c.rowid, c.ref, c.datec,";
2081 $sql .=
" c.tms as date_modification,";
2082 $sql .=
" fk_user_author";
2083 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
2084 $sql .=
" WHERE c.rowid = ".((int) $id);
2086 $result = $this->
db->query($sql);
2088 if ($this->
db->num_rows($result)) {
2089 $obj = $this->
db->fetch_object($result);
2091 $this->
id = $obj->rowid;
2093 if ($obj->fk_user_author) {
2094 $cuser =
new User($this->
db);
2095 $cuser->fetch($obj->fk_user_author);
2096 $this->user_creation = $cuser;
2099 $this->
ref = (!$obj->ref) ? $obj->rowid : $obj->ref;
2100 $this->date_creation = $this->db->jdate($obj->datec);
2101 $this->date_modification = $this->
db->jdate($obj->date_modification);
2104 $this->
db->free($result);
2122 $sql =
"SELECT cd.rowid";
2123 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as cd";
2124 $sql .=
" WHERE fk_contrat =".((int) $this->
id);
2126 $sql .=
" AND statut = ".((int) $status);
2129 dol_syslog(get_class($this).
"::array_detail()", LOG_DEBUG);
2132 $num = $this->
db->num_rows(
$resql);
2135 $obj = $this->
db->fetch_object(
$resql);
2136 $tab[$i] = $obj->rowid;
2141 $this->error = $this->
db->error();
2155 public function getListOfContracts($option =
'all', $status = [], $product_categories = [], $line_status = [])
2159 $sql =
"SELECT c.rowid";
2160 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
2161 if (!empty($product_categories)) {
2162 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"contratdet as cd ON cd.fk_contrat = c.rowid";
2163 $sql .=
" INNER JOIN ".MAIN_DB_PREFIX.
"categorie_product as cp ON cp.fk_product = cd.fk_product AND cp.fk_categorie IN (".$this->
db->sanitize(implode(
', ', $product_categories)).
")";
2165 $sql .=
" WHERE c.fk_soc =".((int) $this->socid);
2166 $sql .= ($option ==
'others') ?
" AND c.rowid <> ".((
int) $this->id) :
"";
2167 $sql .= (!empty($status)) ?
" AND c.statut IN (".$this->
db->sanitize(implode(
', ', $status)).
")" :
"";
2168 $sql .= (!empty($line_status)) ?
" AND cd.statut IN (".$this->
db->sanitize(implode(
', ', $line_status)).
")" :
"";
2169 $sql .=
" GROUP BY c.rowid";
2171 dol_syslog(get_class($this).
"::getOtherContracts()", LOG_DEBUG);
2174 $num = $this->
db->num_rows(
$resql);
2177 $obj = $this->
db->fetch_object(
$resql);
2179 $contrat->fetch($obj->rowid);
2180 $tab[$contrat->id] = $contrat;
2185 $this->error = $this->
db->lasterror();
2202 global $conf, $langs;
2204 $this->from =
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
2205 $this->from .=
", ".MAIN_DB_PREFIX.
"contratdet as cd";
2206 $this->from .=
", ".MAIN_DB_PREFIX.
"societe as s";
2207 if (empty($user->rights->societe->client->voir) && !$user->socid) {
2208 $this->from .=
", ".MAIN_DB_PREFIX.
"societe_commerciaux as sc";
2211 if ($mode ==
'inactive') {
2212 $sql =
"SELECT cd.rowid, cd.date_ouverture_prevue as datefin";
2213 $sql .= $this->from;
2214 $sql .=
" WHERE c.statut = 1";
2215 $sql .=
" AND c.rowid = cd.fk_contrat";
2216 $sql .=
" AND cd.statut = 0";
2217 } elseif ($mode ==
'expired') {
2218 $sql =
"SELECT cd.rowid, cd.date_fin_validite as datefin";
2219 $sql .= $this->from;
2220 $sql .=
" WHERE c.statut = 1";
2221 $sql .=
" AND c.rowid = cd.fk_contrat";
2222 $sql .=
" AND cd.statut = 4";
2223 $sql .=
" AND cd.date_fin_validite < '".$this->db->idate(
dol_now()).
"'";
2224 } elseif ($mode ==
'active') {
2225 $sql =
"SELECT cd.rowid, cd.date_fin_validite as datefin";
2226 $sql .= $this->from;
2227 $sql .=
" WHERE c.statut = 1";
2228 $sql .=
" AND c.rowid = cd.fk_contrat";
2229 $sql .=
" AND cd.statut = 4";
2233 $sql .=
" AND c.fk_soc = s.rowid";
2234 $sql .=
" AND c.entity = ".((int) $conf->entity);
2236 $sql .=
" AND c.fk_soc = ".((int) $user->socid);
2238 if (empty($user->rights->societe->client->voir) && !$user->socid) {
2239 $sql .=
" AND c.fk_soc = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
2244 $langs->load(
"contracts");
2247 if ($mode ==
'inactive') {
2248 $warning_delay = $conf->contrat->services->inactifs->warning_delay;
2249 $label = $langs->trans(
"BoardNotActivatedServices");
2250 $labelShort = $langs->trans(
"BoardNotActivatedServicesShort");
2251 $url = DOL_URL_ROOT.
'/contrat/services_list.php?mainmenu=commercial&leftmenu=contracts&mode=0&sortfield=cd.date_fin_validite&sortorder=asc';
2252 } elseif ($mode ==
'expired') {
2253 $warning_delay = $conf->contrat->services->expires->warning_delay;
2254 $url = DOL_URL_ROOT.
'/contrat/services_list.php?mainmenu=commercial&leftmenu=contracts&mode=4&filter=expired&sortfield=cd.date_fin_validite&sortorder=asc';
2255 $label = $langs->trans(
"BoardExpiredServices");
2256 $labelShort = $langs->trans(
"BoardExpiredServicesShort");
2258 $warning_delay = $conf->contrat->services->expires->warning_delay;
2259 $url = DOL_URL_ROOT.
'/contrat/services_list.php?mainmenu=commercial&leftmenu=contracts&mode=4&sortfield=cd.date_fin_validite&sortorder=asc';
2262 $label = $langs->trans(
"BoardRunningServices");
2263 $labelShort = $langs->trans(
"BoardRunningServicesShort");
2267 $response->warning_delay = $warning_delay / 60 / 60 / 24;
2268 $response->label = $label;
2269 $response->labelShort = $labelShort;
2270 $response->url = $url;
2273 while ($obj = $this->
db->fetch_object(
$resql)) {
2274 $response->nbtodo++;
2276 if ($obj->datefin && $this->db->jdate($obj->datefin) < ($now - $warning_delay)) {
2277 $response->nbtodolate++;
2284 $this->error = $this->
db->error();
2298 global $conf, $user;
2300 $this->nb = array();
2303 $sql =
"SELECT count(c.rowid) as nb";
2304 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contrat as c";
2305 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe as s ON c.fk_soc = s.rowid";
2306 if (empty($user->rights->societe->client->voir) && !$user->socid) {
2307 $sql .=
" LEFT JOIN ".MAIN_DB_PREFIX.
"societe_commerciaux as sc ON s.rowid = sc.fk_soc";
2308 $sql .=
" WHERE sc.fk_user = ".((int) $user->id);
2311 $sql .=
" ".$clause.
" c.entity = ".$conf->entity;
2315 while ($obj = $this->
db->fetch_object(
$resql)) {
2316 $this->nb[
"contracts"] = $obj->nb;
2322 $this->error = $this->
db->error();
2360 global $user, $langs, $conf;
2365 $sql =
"SELECT rowid";
2366 $sql .=
" FROM ".MAIN_DB_PREFIX.
"product";
2367 $sql .=
" WHERE entity IN (".getEntity(
'product').
")";
2368 $sql .=
" AND tosell = 1";
2369 $sql .= $this->
db->plimit(100);
2373 $num_prods = $this->
db->num_rows(
$resql);
2375 while ($i < $num_prods) {
2377 $row = $this->
db->fetch_row(
$resql);
2378 $prodids[$i] = $row[0];
2384 $this->specimen = 1;
2386 $this->
ref =
'SPECIMEN';
2387 $this->ref_customer =
'SPECIMENCUST';
2388 $this->ref_supplier =
'SPECIMENSUPP';
2391 $this->date_creation = (
dol_now() - 3600 * 24 * 7);
2392 $this->date_contrat =
dol_now();
2393 $this->commercial_signature_id = 1;
2394 $this->commercial_suivi_id = 1;
2395 $this->note_private =
'This is a comment (private)';
2396 $this->note_public =
'This is a comment (public)';
2397 $this->fk_projet = 0;
2401 while ($xnbp < $nbp) {
2404 $line->subprice = 100;
2406 $line->tva_tx = 19.6;
2407 $line->remise_percent = 10;
2408 $line->total_ht = 90;
2409 $line->total_ttc = 107.64;
2410 $line->total_tva = 17.64;
2411 $line->date_start =
dol_now() - 500000;
2412 $line->date_start_real =
dol_now() - 200000;
2413 $line->date_end =
dol_now() + 500000;
2414 $line->date_end_real =
dol_now() - 100000;
2415 if ($num_prods > 0) {
2416 $prodid = mt_rand(1, $num_prods);
2417 $line->fk_product = $prodids[$prodid];
2419 $this->lines[$xnbp] = $line;
2446 public function generateDocument($modele, $outputlangs, $hidedetails = 0, $hidedesc = 0, $hideref = 0, $moreparams =
null)
2448 global $conf, $langs;
2453 if (!empty($this->model_pdf)) {
2454 $modele = $this->model_pdf;
2455 } elseif (!empty($this->modelpdf)) {
2456 $modele = $this->modelpdf;
2457 } elseif (!empty($conf->global->CONTRACT_ADDON_PDF)) {
2458 $modele = $conf->global->CONTRACT_ADDON_PDF;
2462 if (empty($modele)) {
2465 $langs->load(
"contracts");
2466 $outputlangs->load(
"products");
2468 $modelpath =
"core/modules/contract/doc/";
2469 return $this->
commonGenerateDocument($modelpath, $modele, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
2517 global $db, $langs, $conf, $hookmanager, $extrafields;
2523 $this->
fetch($this->
id);
2526 $clonedObj = clone $this;
2527 $clonedObj->socid = $socid;
2533 $objsoc->fetch($clonedObj->socid);
2536 $clonedObj->statut = 0;
2538 if (is_array($clonedObj->array_options) && count($clonedObj->array_options) > 0) {
2539 $extrafields->fetch_name_optionals_label($this->table_element);
2540 foreach ($clonedObj->array_options as $key => $option) {
2541 $shortkey = preg_replace(
'/options_/',
'', $key);
2543 if (!empty($extrafields->attributes[$this->element][
'unique'][$shortkey])) {
2545 unset($clonedObj->array_options[$key]);
2550 if (empty($conf->global->CONTRACT_ADDON) || !is_readable(DOL_DOCUMENT_ROOT.
"/core/modules/contract/".$conf->global->CONTRACT_ADDON.
".php")) {
2551 $this->error =
'ErrorSetupNotComplete';
2557 require_once DOL_DOCUMENT_ROOT.
"/core/modules/contract/".$conf->global->CONTRACT_ADDON.
'.php';
2558 $obj = $conf->global->CONTRACT_ADDON;
2559 $modContract =
new $obj();
2560 $clonedObj->ref = $modContract->getNextValue($objsoc, $clonedObj);
2563 foreach ($this->lines as $line) {
2564 $line->fetch_optionals($line->id);
2568 $clonedObj->context[
'createfromclone'] =
'createfromclone';
2569 $result = $clonedObj->create($user);
2572 $this->error = $clonedObj->error;
2573 $this->errors[] = $clonedObj->error;
2576 if ($this->socid == $clonedObj->socid) {
2577 if ($clonedObj->copy_linked_contact($this,
'external') < 0) {
2584 foreach ($this->lines as $line) {
2585 $result = $clonedObj->addline($line->description, $line->subprice, $line->qty, $line->tva_tx, $line->localtax1_tx, $line->localtax2_tx, $line->fk_product, $line->remise_percent, $line->date_ouverture, $line->date_cloture,
'HT', 0, $line->info_bits, $line->fk_fournprice, $line->pa_ht, $line->array_options, $line->fk_unit, $line->rang);
2588 $this->error = $clonedObj->error;
2589 $this->errors[] = $clonedObj->error;
2596 if (is_object($hookmanager)) {
2597 $parameters = array(
2599 'clonedObj' => $clonedObj
2602 $reshook = $hookmanager->executeHooks(
'createFrom', $parameters, $clonedObj, $action);
2604 $this->errors += $hookmanager->errors;
2605 $this->error = $hookmanager->error;
2611 unset($clonedObj->context[
'createfromclone']);
2615 $this->
db->commit();
2616 return $clonedObj->id;
2618 $this->
db->rollback();
2635 global $langs, $user;
2637 $langs->load(
"agenda");
2647 $contractlineprocessed = array();
2648 $contractignored = array();
2649 $contracterror = array();
2653 $sql =
'SELECT c.rowid, c.ref_customer, cd.rowid as lid, cd.date_fin_validite, p.duration';
2654 $sql.=
' FROM '.MAIN_DB_PREFIX.
'contrat as c, '.MAIN_DB_PREFIX.
'contratdet as cd';
2655 $sql.=
' LEFT JOIN '.MAIN_DB_PREFIX.
'product as p ON p.rowid = cd.fk_product';
2656 $sql.=
' WHERE cd.fk_contrat = c.rowid';
2657 $sql.=
" AND date_format(cd.date_fin_validite, '%Y-%m-%d') <= date_format('".$this->db->idate($enddatetoscan).
"', '%Y-%m-%d')";
2658 $sql.=
" AND cd.statut = 4";
2659 if ($thirdparty_id > 0) $sql.=
" AND c.fk_soc = ".((int) $thirdparty_id);
2664 $num = $this->
db->num_rows(
$resql);
2666 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formmail.class.php';
2670 $obj = $this->
db->fetch_object(
$resql);
2672 if (!empty($contractlineprocessed[$obj->lid]) || !empty($contractignored[$obj->rowid]) || !empty($contracterror[$obj->rowid])) {
2678 $object->fetch($obj->rowid);
2679 $object->fetch_thirdparty();
2681 if ($object->id <= 0) {
2683 $this->errors[] =
'Failed to load contract with id='.$obj->rowid;
2687 dol_syslog(
"* Process contract line in doRenewalContracts for contract id=".$object->id.
" ref=".$object->ref.
" ref_customer=".$object->ref_customer.
" contract line id=".$obj->lid);
2690 $expirationdate = $this->
db->jdate($obj->date_fin_validite);
2691 $duration_value = preg_replace(
'/[^0-9]/',
'', $obj->duration);
2692 $duration_unit = preg_replace(
'/\d/',
'', $obj->duration);
2696 $object->fetchObjectLinked(
null,
'',
null,
'',
'OR', 1,
'sourcetype', 1);
2698 if (is_array($object->linkedObjects[
'facture']) && count($object->linkedObjects[
'facture']) > 0) {
2699 usort($object->linkedObjects[
'facture'],
"cmp");
2702 $someinvoicenotpaid=0;
2703 foreach ($object->linkedObjects[
'facture'] as $idinvoice => $invoice) {
2706 if (empty($invoice->paye)) {
2707 $someinvoicenotpaid++;
2710 if ($someinvoicenotpaid) {
2711 $this->output .=
'Contract '.$object->ref.
' is qualified for renewal but there is '.$someinvoicenotpaid.
' invoice(s) unpayed so we cancel renewal'.
"\n";
2712 $contractignored[$object->id]=$object->ref;
2717 if ($expirationdate && $expirationdate < $enddatetoscan) {
2718 dol_syslog(
"Define the newdate of end of services from expirationdate=".$expirationdate);
2719 $newdate = $expirationdate;
2721 while ($newdate < $enddatetoscan && $protecti < 1000) {
2726 if ($protecti < 1000) {
2732 $errorforlocaltransaction = 0;
2734 $label =
'Renewal of contrat '.$object->ref.
' line '.$obj->lid;
2735 $comment =
'Renew date of contract '.$object->ref.
' line '.$obj->lid.
' by doAutoRenewContracts';
2737 $sqlupdate =
'UPDATE '.MAIN_DB_PREFIX.
"contratdet SET date_fin_validite = '".$this->
db->idate($newdate).
"'";
2738 $sqlupdate.=
' WHERE rowid = '.((int) $obj->lid);
2739 $resqlupdate = $this->
db->query($sqlupdate);
2741 $contractlineprocessed[$obj->lid]=$object->ref;
2743 $actioncode =
'RENEW_CONTRACT';
2748 $actioncomm->type_code =
'AC_OTH_AUTO';
2749 $actioncomm->code =
'AC_'.$actioncode;
2750 $actioncomm->label = $label;
2751 $actioncomm->datep = $now;
2752 $actioncomm->datef = $now;
2753 $actioncomm->percentage = -1;
2754 $actioncomm->socid = $object->thirdparty->id;
2755 $actioncomm->authorid = $user->id;
2756 $actioncomm->userownerid = $user->id;
2757 $actioncomm->fk_element = $object->id;
2758 $actioncomm->elementtype =
'contract';
2759 $actioncomm->note_private = $comment;
2761 $ret = $actioncomm->create($user);
2763 $contracterror[$object->id]=$object->ref;
2766 $errorforlocaltransaction++;
2767 $this->error = $this->
db->lasterror();
2770 if (! $errorforlocaltransaction) {
2771 $this->
db->commit();
2773 $this->
db->rollback();
2777 $this->error =
"Bad value for newdate in doAutoRenewContracts - expirationdate=".$expirationdate.
" enddatetoscan=".$enddatetoscan.
" duration_value=".$duration_value.
" duration_unit=".$duration_value;
2786 $this->error = $this->
db->lasterror();
2789 $this->output .= count($contractlineprocessed).
' contract line(s) with end date before '.
dol_print_date($enddatetoscan,
'day').
' were renewed'.(count($contractlineprocessed)>0 ?
' : '.join(
',', $contractlineprocessed) :
'');
2791 return ($error ? 1: 0);
2804 public $element =
'contratdet';
2809 public $table_element =
'contratdet';
2815 public $element_for_permission =
'contrat';
2857 public $description;
2859 public $product_type;
2860 public $product_ref;
2861 public $product_label;
2863 public $date_commande;
2866 public $date_start_real;
2868 public $date_end_real;
2871 public $vat_src_code;
2872 public $localtax1_tx;
2873 public $localtax2_tx;
2874 public $localtax1_type;
2875 public $localtax2_type;
2877 public $remise_percent;
2883 public $fk_remise_except;
2898 public $total_localtax1;
2899 public $total_localtax2;
2905 public $fk_fournprice;
2914 public $fk_user_author;
2919 public $fk_user_ouverture;
2924 public $fk_user_cloture;
2926 public $commentaire;
2935 const STATUS_INITIAL = 0;
2936 const STATUS_OPEN = 4;
2937 const STATUS_CLOSED = 5;
2944 public $fields = array(
2945 'rowid' =>array(
'type'=>
'integer',
'label'=>
'TechnicalID',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>10),
2946 'entity' =>array(
'type'=>
'integer',
'label'=>
'Entity',
'default'=>1,
'enabled'=>1,
'visible'=>-2,
'notnull'=>1,
'position'=>30,
'index'=>1),
2947 'tms' =>array(
'type'=>
'timestamp',
'label'=>
'DateModification',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>35),
2948 'qty' =>array(
'type'=>
'integer',
'label'=>
'Quantity',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>35,
'isameasure'=>1),
2949 'total_ht' =>array(
'type'=>
'integer',
'label'=>
'AmountHT',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>36,
'isameasure'=>1),
2950 'total_tva' =>array(
'type'=>
'integer',
'label'=>
'AmountVAT',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>37,
'isameasure'=>1),
2951 'total_ttc' =>array(
'type'=>
'integer',
'label'=>
'AmountTTC',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>38,
'isameasure'=>1),
2954 'fk_contrat' =>array(
'type'=>
'integer:Contrat:contrat/class/contrat.class.php',
'label'=>
'Contract',
'enabled'=>1,
'visible'=>-1,
'notnull'=>1,
'position'=>70),
2955 'fk_product' =>array(
'type'=>
'integer:Product:product/class/product.class.php:1',
'label'=>
'Product',
'enabled'=>1,
'visible'=>-1,
'position'=>75),
2957 'note_private' =>array(
'type'=>
'text',
'label'=>
'NotePublic',
'enabled'=>1,
'visible'=>0,
'position'=>105),
2958 'note_public' =>array(
'type'=>
'text',
'label'=>
'NotePrivate',
'enabled'=>1,
'visible'=>0,
'position'=>110),
2962 'fk_user_ouverture' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserStartingService',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>135),
2963 'fk_user_cloture' =>array(
'type'=>
'integer:User:user/class/user.class.php',
'label'=>
'UserClosingService',
'enabled'=>1,
'visible'=>-2,
'notnull'=>-1,
'position'=>135),
2964 'statut' =>array(
'type'=>
'smallint(6)',
'label'=>
'Statut',
'enabled'=>1,
'visible'=>-1,
'position'=>500,
'arrayofkeyval'=>array(0=>
'Draft', 4=>
'Open', 5=>
'Closed')),
2965 'rang' =>array(
'type'=>
'integer',
'label'=>
'Rank',
'enabled'=>1,
'visible'=>0,
'position'=>500,
'default' =>0)
2989 return $this->
LibStatut($this->statut, $mode, ((!empty($this->date_end)) ? ($this->date_end <
dol_now() ? 1 : 0) : -1));
3002 public static function LibStatut($status, $mode, $expired = -1, $moreatt =
'')
3006 $langs->load(
"contracts");
3008 if ($status == self::STATUS_INITIAL) {
3009 $labelStatus = $langs->transnoentities(
"ServiceStatusInitial");
3010 $labelStatusShort = $langs->transnoentities(
"ServiceStatusInitial");
3011 } elseif ($status == self::STATUS_OPEN && $expired == -1) {
3012 $labelStatus = $langs->transnoentities(
"ServiceStatusRunning");
3013 $labelStatusShort = $langs->transnoentities(
"ServiceStatusRunning");
3014 } elseif ($status == self::STATUS_OPEN && $expired == 0) {
3015 $labelStatus = $langs->transnoentities(
"ServiceStatusNotLate");
3016 $labelStatusShort = $langs->transnoentities(
"ServiceStatusNotLateShort");
3017 } elseif ($status == self::STATUS_OPEN && $expired == 1) {
3018 $labelStatus = $langs->transnoentities(
"ServiceStatusLate");
3019 $labelStatusShort = $langs->transnoentities(
"ServiceStatusLateShort");
3020 } elseif ($status == self::STATUS_CLOSED) {
3021 $labelStatus = $langs->transnoentities(
"ServiceStatusClosed");
3022 $labelStatusShort = $langs->transnoentities(
"ServiceStatusClosed");
3025 $statusType =
'status'.$status;
3026 if ($status == self::STATUS_OPEN && $expired == 1) {
3027 $statusType =
'status1';
3029 if ($status == self::STATUS_CLOSED) {
3030 $statusType =
'status6';
3033 $params = array(); $reg = array();
3034 if (preg_match(
'/class="(.*)"/', $moreatt, $reg)) {
3035 $params = array(
'badgeParams'=>array(
'css' => $reg[1]));
3037 return dolGetStatus($labelStatus, $labelStatusShort,
'', $statusType, $mode,
'', $params);
3052 $label = $langs->trans(
"ShowContractOfService").
': '.$this->label;
3053 if (empty($label)) {
3054 $label = $this->description;
3057 $link =
'<a href="'.DOL_URL_ROOT.
'/contrat/card.php?id='.$this->fk_contrat.
'" title="'.
dol_escape_htmltag($label, 1).
'" class="classfortooltip">';
3061 if ($this->
type == 0) {
3066 $result .= ($link.img_object($label, $picto,
'class="classfortooltip"').$linkend);
3068 if ($withpicto && $withpicto != 2) {
3071 if ($withpicto != 2) {
3072 $result .= $link.($this->product_ref ? $this->product_ref.
' ' :
'').($this->label ? $this->label : $this->
description).$linkend;
3087 if (empty($id) && empty($ref)) {
3092 $sql .=
" t.rowid,";
3094 $sql .=
" t.fk_contrat,";
3095 $sql .=
" t.fk_product,";
3096 $sql .=
" t.statut,";
3097 $sql .=
" t.label,";
3098 $sql .=
" p.ref as product_ref,";
3099 $sql .=
" p.label as product_label,";
3100 $sql .=
" p.description as product_desc,";
3101 $sql .=
" p.fk_product_type as product_type,";
3102 $sql .=
" t.description,";
3103 $sql .=
" t.date_commande,";
3104 $sql .=
" t.date_ouverture_prevue as date_start,";
3105 $sql .=
" t.date_ouverture as date_start_real,";
3106 $sql .=
" t.date_fin_validite as date_end,";
3107 $sql .=
" t.date_cloture as date_end_real,";
3108 $sql .=
" t.tva_tx,";
3109 $sql .=
" t.vat_src_code,";
3110 $sql .=
" t.localtax1_tx,";
3111 $sql .=
" t.localtax2_tx,";
3112 $sql .=
" t.localtax1_type,";
3113 $sql .=
" t.localtax2_type,";
3115 $sql .=
" t.remise_percent,";
3116 $sql .=
" t.remise,";
3117 $sql .=
" t.fk_remise_except,";
3118 $sql .=
" t.subprice,";
3119 $sql .=
" t.price_ht,";
3120 $sql .=
" t.total_ht,";
3121 $sql .=
" t.total_tva,";
3122 $sql .=
" t.total_localtax1,";
3123 $sql .=
" t.total_localtax2,";
3124 $sql .=
" t.total_ttc,";
3125 $sql .=
" t.fk_product_fournisseur_price as fk_fournprice,";
3126 $sql .=
" t.buy_price_ht as pa_ht,";
3127 $sql .=
" t.info_bits,";
3128 $sql .=
" t.fk_user_author,";
3129 $sql .=
" t.fk_user_ouverture,";
3130 $sql .=
" t.fk_user_cloture,";
3131 $sql .=
" t.commentaire,";
3132 $sql .=
" t.fk_unit,";
3134 $sql .=
" FROM ".MAIN_DB_PREFIX.
"contratdet as t LEFT JOIN ".MAIN_DB_PREFIX.
"product as p ON p.rowid = t.fk_product";
3136 $sql .=
" WHERE t.rowid = ".((int) $id);
3139 $sql .=
" WHERE t.rowid = '".$this->db->escape($ref).
"'";
3142 dol_syslog(get_class($this).
"::fetch", LOG_DEBUG);
3146 $obj = $this->
db->fetch_object(
$resql);
3148 $this->
id = $obj->rowid;
3149 $this->
ref = $obj->rowid;
3151 $this->tms = $this->
db->jdate($obj->tms);
3152 $this->fk_contrat = $obj->fk_contrat;
3153 $this->fk_product = $obj->fk_product;
3154 $this->statut = $obj->statut;
3155 $this->product_ref = $obj->product_ref;
3156 $this->product_label = $obj->product_label;
3157 $this->product_description = $obj->product_description;
3158 $this->product_type = $obj->product_type;
3159 $this->label = $obj->label;
3161 $this->date_commande = $this->
db->jdate($obj->date_commande);
3163 $this->date_start = $this->
db->jdate($obj->date_start);
3164 $this->date_start_real = $this->
db->jdate($obj->date_start_real);
3165 $this->date_end = $this->
db->jdate($obj->date_end);
3166 $this->date_end_real = $this->
db->jdate($obj->date_end_real);
3173 $this->tva_tx = $obj->tva_tx;
3174 $this->vat_src_code = $obj->vat_src_code;
3175 $this->localtax1_tx = $obj->localtax1_tx;
3176 $this->localtax2_tx = $obj->localtax2_tx;
3177 $this->localtax1_type = $obj->localtax1_type;
3178 $this->localtax2_type = $obj->localtax2_type;
3179 $this->qty = $obj->qty;
3180 $this->remise_percent = $obj->remise_percent;
3181 $this->fk_remise_except = $obj->fk_remise_except;
3182 $this->subprice = $obj->subprice;
3183 $this->price_ht = $obj->price_ht;
3184 $this->total_ht = $obj->total_ht;
3185 $this->total_tva = $obj->total_tva;
3186 $this->total_localtax1 = $obj->total_localtax1;
3187 $this->total_localtax2 = $obj->total_localtax2;
3188 $this->total_ttc = $obj->total_ttc;
3189 $this->info_bits = $obj->info_bits;
3190 $this->fk_user_author = $obj->fk_user_author;
3191 $this->fk_user_ouverture = $obj->fk_user_ouverture;
3192 $this->fk_user_cloture = $obj->fk_user_cloture;
3193 $this->commentaire = $obj->commentaire;
3194 $this->fk_fournprice = $obj->fk_fournprice;
3196 $marginInfos =
getMarginInfos($obj->subprice, $obj->remise_percent, $obj->tva_tx, $obj->localtax1_tx, $obj->localtax2_tx, $this->fk_fournprice, $obj->pa_ht);
3197 $this->pa_ht = $marginInfos[0];
3198 $this->fk_unit = $obj->fk_unit;
3200 $this->rang = $obj->rang;
3209 $this->error =
"Error ".$this->db->lasterror();
3222 public function update($user, $notrigger = 0)
3224 global $conf, $langs, $mysoc;
3229 $this->fk_contrat = (int) $this->fk_contrat;
3230 $this->fk_product = (int) $this->fk_product;
3231 $this->statut = (int) $this->statut;
3232 $this->label = trim($this->label);
3234 $this->vat_src_code = trim($this->vat_src_code);
3235 $this->tva_tx = trim($this->tva_tx);
3236 $this->localtax1_tx = trim($this->localtax1_tx);
3237 $this->localtax2_tx = trim($this->localtax2_tx);
3238 $this->qty = trim($this->qty);
3239 $this->remise_percent = trim($this->remise_percent);
3240 $this->fk_remise_except = (int) $this->fk_remise_except;
3241 $this->subprice =
price2num($this->subprice);
3242 $this->price_ht =
price2num($this->price_ht);
3243 $this->total_ht = trim($this->total_ht);
3244 $this->total_tva = trim($this->total_tva);
3245 $this->total_localtax1 = trim($this->total_localtax1);
3246 $this->total_localtax2 = trim($this->total_localtax2);
3247 $this->total_ttc = trim($this->total_ttc);
3248 $this->info_bits = trim($this->info_bits);
3249 $this->fk_user_author = (int) $this->fk_user_author;
3250 $this->fk_user_ouverture = (int) $this->fk_user_ouverture;
3251 $this->fk_user_cloture = (int) $this->fk_user_cloture;
3252 $this->commentaire = trim($this->commentaire);
3253 $this->rang = (int) $this->rang;
3255 if (empty($this->price_ht)) {
3256 $this->price_ht = 0;
3258 if (empty($this->total_ht)) {
3259 $this->total_ht = 0;
3261 if (empty($this->total_tva)) {
3262 $this->total_tva = 0;
3264 if (empty($this->total_ttc)) {
3265 $this->total_ttc = 0;
3267 if (empty($this->localtax1_tx)) {
3268 $this->localtax1_tx = 0;
3270 if (empty($this->localtax2_tx)) {
3271 $this->localtax2_tx = 0;
3273 if (empty($this->remise_percent)) {
3274 $this->remise_percent = 0;
3277 if (empty($this->date_start)) {
3278 $this->date_start = $this->date_start;
3280 if (empty($this->date_start_real)) {
3281 $this->date_start_real = $this->date_start_real;
3283 if (empty($this->date_end)) {
3284 $this->date_end = $this->date_end;
3286 if (empty($this->date_end_real)) {
3287 $this->date_end_real = $this->date_end_real;
3296 $tabprice =
calcul_price_total($this->qty, $this->price_ht, $this->remise_percent, $this->tva_tx, $this->localtax1_tx, $this->localtax2_tx, 0,
'HT', 0, 1, $mysoc, $localtaxes_type);
3297 $this->total_ht = $tabprice[0];
3298 $this->total_tva = $tabprice[1];
3299 $this->total_ttc = $tabprice[2];
3300 $this->total_localtax1 = $tabprice[9];
3301 $this->total_localtax2 = $tabprice[10];
3303 if (empty($this->pa_ht)) {
3308 if ($this->pa_ht == 0) {
3309 if (($result = $this->
defineBuyPrice($this->subprice, $this->remise_percent, $this->fk_product)) < 0) {
3312 $this->pa_ht = $result;
3317 if (empty($this->oldcopy)) {
3324 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contratdet SET";
3325 $sql .=
" fk_contrat = ".((int) $this->fk_contrat).
",";
3326 $sql .=
" fk_product = ".($this->fk_product ? ((int) $this->fk_product) :
'null').
",";
3327 $sql .=
" statut = ".((int) $this->statut).
",";
3328 $sql .=
" label = '".$this->db->escape($this->label).
"',";
3329 $sql .=
" description = '".$this->db->escape($this->
description).
"',";
3330 $sql .=
" date_commande = ".($this->date_commande !=
'' ?
"'".$this->db->idate($this->date_commande).
"'" :
"null").
",";
3331 $sql .=
" date_ouverture_prevue = ".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
"null").
",";
3332 $sql .=
" date_ouverture = ".($this->date_start_real !=
'' ?
"'".$this->db->idate($this->date_start_real).
"'" :
"null").
",";
3333 $sql .=
" date_fin_validite = ".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
3334 $sql .=
" date_cloture = ".($this->date_end_real !=
'' ?
"'".$this->db->idate($this->date_end_real).
"'" :
"null").
",";
3335 $sql .=
" vat_src_code = '".$this->db->escape($this->vat_src_code).
"',";
3336 $sql .=
" tva_tx = ".price2num($this->tva_tx).
",";
3337 $sql .=
" localtax1_tx = ".price2num($this->localtax1_tx).
",";
3338 $sql .=
" localtax2_tx = ".price2num($this->localtax2_tx).
",";
3339 $sql .=
" qty = ".price2num($this->qty).
",";
3340 $sql .=
" remise_percent = ".price2num($this->remise_percent).
",";
3341 $sql .=
" remise = ".($this->remise ?
price2num($this->remise) :
"null").
",";
3342 $sql .=
" fk_remise_except = ".($this->fk_remise_except > 0 ? $this->fk_remise_except :
"null").
",";
3343 $sql .=
" subprice = ".($this->subprice !=
'' ? $this->subprice :
"null").
",";
3344 $sql .=
" price_ht = ".($this->price_ht !=
'' ? $this->price_ht :
"null").
",";
3345 $sql .=
" total_ht = ".$this->total_ht.
",";
3346 $sql .=
" total_tva = ".$this->total_tva.
",";
3347 $sql .=
" total_localtax1 = ".$this->total_localtax1.
",";
3348 $sql .=
" total_localtax2 = ".$this->total_localtax2.
",";
3349 $sql .=
" total_ttc = ".$this->total_ttc.
",";
3350 $sql .=
" fk_product_fournisseur_price = ".(!empty($this->fk_fournprice) ? $this->fk_fournprice :
"NULL").
",";
3351 $sql .=
" buy_price_ht = '".price2num($this->pa_ht).
"',";
3352 $sql .=
" info_bits = '".$this->db->escape($this->info_bits).
"',";
3353 $sql .=
" fk_user_author = ".($this->fk_user_author >= 0 ? $this->fk_user_author :
"NULL").
",";
3354 $sql .=
" fk_user_ouverture = ".($this->fk_user_ouverture > 0 ? $this->fk_user_ouverture :
"NULL").
",";
3355 $sql .=
" fk_user_cloture = ".($this->fk_user_cloture > 0 ? $this->fk_user_cloture :
"NULL").
",";
3356 $sql .=
" commentaire = '".$this->db->escape($this->commentaire).
"',";
3357 $sql .=
" fk_unit = ".(!$this->fk_unit ?
'NULL' : $this->fk_unit).
",";
3358 $sql .=
" rang = ".(empty($this->rang) ?
'0' : (int) $this->rang);
3359 $sql .=
" WHERE rowid = ".((int) $this->
id);
3361 dol_syslog(get_class($this).
"::update", LOG_DEBUG);
3364 $this->error =
"Error ".$this->db->lasterror();
3376 if (!$error && !empty($conf->global->CONTRACT_SYNC_PLANNED_DATE_OF_SERVICES)) {
3377 dol_syslog(get_class($this).
"::update CONTRACT_SYNC_PLANNED_DATE_OF_SERVICES is on so we update date for all lines", LOG_DEBUG);
3379 if ($this->date_start != $this->oldcopy->date_start) {
3380 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'contratdet SET';
3381 $sql .=
" date_ouverture_prevue = ".($this->date_start !=
'' ?
"'".$this->db->idate($this->date_start).
"'" :
"null");
3382 $sql .=
" WHERE fk_contrat = ".((int) $this->fk_contrat);
3387 $this->error =
"Error ".$this->db->lasterror();
3390 if ($this->date_end != $this->oldcopy->date_end) {
3391 $sql =
'UPDATE '.MAIN_DB_PREFIX.
'contratdet SET';
3392 $sql .=
" date_fin_validite = ".($this->date_end !=
'' ?
"'".$this->db->idate($this->date_end).
"'" :
"null");
3393 $sql .=
" WHERE fk_contrat = ".((int) $this->fk_contrat);
3398 $this->error =
"Error ".$this->db->lasterror();
3403 if (!$error && !$notrigger) {
3405 $result = $this->
call_trigger(
'LINECONTRACT_MODIFY', $user);
3408 $this->
db->rollback();
3414 $this->
db->commit();
3417 $this->
db->rollback();
3418 $this->errors[] = $this->error;
3437 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contratdet SET";
3438 $sql .=
" total_ht=".price2num($this->total_ht,
'MT').
"";
3439 $sql .=
",total_tva=".price2num($this->total_tva,
'MT').
"";
3440 $sql .=
",total_localtax1=".price2num($this->total_localtax1,
'MT').
"";
3441 $sql .=
",total_localtax2=".price2num($this->total_localtax2,
'MT').
"";
3442 $sql .=
",total_ttc=".price2num($this->total_ttc,
'MT').
"";
3443 $sql .=
" WHERE rowid = ".((int) $this->
id);
3445 dol_syslog(get_class($this).
"::update_total", LOG_DEBUG);
3449 $this->
db->commit();
3452 $this->error = $this->
db->error();
3453 $this->
db->rollback();
3467 global $conf, $user;
3472 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"contratdet";
3473 $sql .=
" (fk_contrat, label, description, fk_product, qty, vat_src_code, tva_tx,";
3474 $sql .=
" localtax1_tx, localtax2_tx, localtax1_type, localtax2_type, remise_percent, subprice,";
3475 $sql .=
" total_ht, total_tva, total_localtax1, total_localtax2, total_ttc,";
3476 $sql .=
" info_bits,";
3478 $sql .=
" price_ht, remise, fk_product_fournisseur_price, buy_price_ht";
3479 if ($this->date_start > 0) {
3480 $sql .=
",date_ouverture_prevue";
3482 if ($this->date_end > 0) {
3483 $sql .=
",date_fin_validite";
3485 $sql .=
") VALUES ($this->fk_contrat, '', '".$this->db->escape($this->
description).
"',";
3486 $sql .= ($this->fk_product > 0 ? $this->fk_product :
"null").
",";
3487 $sql .=
" '".$this->db->escape($this->qty).
"',";
3488 $sql .=
" '".$this->db->escape($this->vat_src_code).
"',";
3489 $sql .=
" '".$this->db->escape($this->tva_tx).
"',";
3490 $sql .=
" '".$this->db->escape($this->localtax1_tx).
"',";
3491 $sql .=
" '".$this->db->escape($this->localtax2_tx).
"',";
3492 $sql .=
" '".$this->db->escape($this->localtax1_type).
"',";
3493 $sql .=
" '".$this->db->escape($this->localtax2_type).
"',";
3494 $sql .=
" ".price2num($this->remise_percent).
",".
price2num($this->subprice).
",";
3495 $sql .=
" ".price2num($this->total_ht).
",".
price2num($this->total_tva).
",".
price2num($this->total_localtax1).
",".
price2num($this->total_localtax2).
",".
price2num($this->total_ttc).
",";
3496 $sql .=
" '".$this->db->escape($this->info_bits).
"',";
3497 $sql .=
" ".(empty($this->rang) ?
'0' : (int) $this->rang).
",";
3498 $sql .=
" ".price2num($this->price_ht).
",".
price2num($this->remise).
",";
3499 if ($this->fk_fournprice > 0) {
3500 $sql .=
' '.((int) $this->fk_fournprice).
',';
3504 if ($this->pa_ht > 0) {
3505 $sql .=
' '.((float)
price2num($this->pa_ht));
3509 if ($this->date_start > 0) {
3510 $sql .=
",'".$this->db->idate($this->date_start).
"'";
3512 if ($this->date_end > 0) {
3513 $sql .=
",'".$this->db->idate($this->date_end).
"'";
3517 dol_syslog(get_class($this).
"::insert", LOG_DEBUG);
3521 $this->
id = $this->
db->last_insert_id(MAIN_DB_PREFIX.
'contratdet');
3527 $this->
db->rollback();
3534 $result = $this->
call_trigger(
'LINECONTRACT_INSERT', $user);
3536 $this->
db->rollback();
3542 $this->
db->commit();
3545 $this->
db->rollback();
3546 $this->error = $this->
db->error().
" sql=".$sql;
3561 public function active_line($user, $date, $date_end =
'', $comment =
'')
3564 global $langs, $conf;
3570 $this->statut = ContratLigne::STATUS_OPEN;
3571 $this->date_start_real = $date;
3572 $this->date_end = $date_end;
3573 $this->fk_user_ouverture = $user->id;
3574 $this->date_end_real =
null;
3575 $this->commentaire = $comment;
3577 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contratdet SET statut = ".((int) $this->statut).
",";
3578 $sql .=
" date_ouverture = ".(dol_strlen($this->date_start_real) != 0 ?
"'".$this->db->idate($this->date_start_real).
"'" :
"null").
",";
3579 if ($date_end >= 0) {
3580 $sql .=
" date_fin_validite = ".(dol_strlen($this->date_end) != 0 ?
"'".$this->db->idate($this->date_end).
"'" :
"null").
",";
3582 $sql .=
" fk_user_ouverture = ".((int) $this->fk_user_ouverture).
",";
3583 $sql .=
" date_cloture = null,";
3584 $sql .=
" commentaire = '".$this->db->escape($comment).
"'";
3585 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND (statut = ".ContratLigne::STATUS_INITIAL.
" OR statut = ".ContratLigne::STATUS_CLOSED.
")";
3587 dol_syslog(get_class($this).
"::active_line", LOG_DEBUG);
3591 $result = $this->
call_trigger(
'LINECONTRACT_ACTIVATE', $user);
3598 $this->
db->commit();
3601 $this->
db->rollback();
3605 $this->error = $this->
db->lasterror();
3606 $this->
db->rollback();
3621 public function close_line($user, $date_end_real, $comment =
'', $notrigger = 0)
3624 global $langs, $conf;
3627 $this->date_cloture = $date_end_real;
3628 $this->date_end_real = $date_end_real;
3629 $this->fk_user_cloture = $user->id;
3630 $this->commentaire = $comment;
3638 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"contratdet SET statut = ".((int) ContratLigne::STATUS_CLOSED).
",";
3639 $sql .=
" date_cloture = '".$this->db->idate($date_end_real).
"',";
3640 $sql .=
" fk_user_cloture = ".((int) $user->id).
",";
3641 $sql .=
" commentaire = '".$this->db->escape($comment).
"'";
3642 $sql .=
" WHERE rowid = ".((int) $this->
id).
" AND statut = ".((int) ContratLigne::STATUS_OPEN);
3648 $result = $this->
call_trigger(
'LINECONTRACT_CLOSE', $user);
3651 $this->
db->rollback();
3657 $this->
db->commit();
3660 $this->error = $this->
db->lasterror();
3661 $this->
db->rollback();