77@phan-var-force int $error
78@phan-var-force ?string $permissiontoadd
79@phan-var-force ?string $permissiontoread
80@phan-var-force ?string $permissiontodelete
81@phan-var-force ?string $permissiontoclose
82@phan-var-force ?string $permissiontoapprove
83@phan-var-force ?int[] $toselect
84@phan-var-force ?string $diroutputmassaction
85@phan-var-force ?string $objectlabel
86@phan-var-force ?string $option
87@phan-var-force int $deliveryreceipt
88@phan-var-force string $month
89@phan-var-force string $year
90@phan-var-force ?array<string,mixed> $moreparams
91@phan-var-force ?string $search_status
92@phan-var-force ?int $hidedetails
93@phan-var-force ?int $hidedesc
94@phan-var-force ?int $hideref
95@phan-var-force string $confirm
100if (empty($objectclass) || empty($uploaddir)) {
101 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $objectclass or $uploaddir was not defined');
104if (empty($massaction)) {
110@phan-var-force "CommonObject"|"CommandeFournisseur"|"ConferenceOrBoothAttendee"|"Contrat"|"Contact"|"Expedition"|"ExpenseReport"|"Facture"|"FactureFournisseur"|"Fichinter"|"Holiday"|"Partnership"|"Project"|"Propal"|"Societe"|"SupplierProposal" $objectclass
111@phan-var-force string $massaction
112@phan-var-force string $uploaddir
119if (!empty($permtoread) && empty($permissiontoread)) {
120 $permissiontoread = $permtoread;
122if (!empty($permtocreate) && empty($permissiontoadd)) {
123 $permissiontoadd = $permtocreate;
125if (!empty($permtodelete) && empty($permissiontodelete)) {
126 $permissiontodelete = $permtodelete;
130$maxformassaction =
getDolGlobalInt(
'MAIN_LIMIT_FOR_MASS_ACTIONS', 1000);
131if ($massaction && is_array($toselect) && count($toselect) < 1) {
133 setEventMessages($langs->trans(
"NoRecordSelected"),
null,
"warnings");
135if (!$error && isset($toselect) && is_array($toselect) && count($toselect) > $maxformassaction) {
136 setEventMessages($langs->trans(
'TooManyRecordForMassAction', $maxformassaction),
null,
'errors');
143if (!$error && $massaction && !empty($toselect) && is_array($toselect)) {
144 $objecttmpforaccesscheck =
new $objectclass($db);
146 if (!empty($refusedids)) {
147 $langs->load(
"errors");
148 setEventMessages($langs->trans(
"NotEnoughPermissions"),
null,
'errors');
153if (!$error && $massaction ==
'confirm_presend' && !
GETPOST(
'sendmail')) {
154 $massaction =
'presend';
157if (!$error && $massaction ==
'confirm_presend') {
161 $langs->load(
"mails");
162 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
163 include_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
165 $listofobjectid = array();
166 $listofobjectthirdparties = array();
167 $listofobjectcontacts = array();
168 $listofobjectref = array();
169 $contactidtosend = array();
170 $attachedfilesThirdpartyObj = array();
171 $oneemailperrecipient = (
GETPOSTINT(
'oneemailperrecipient') ? 1 : 0);
175 $objecttmp =
new $objectclass($db);
178 $thirdparty =
new Societe($db);
179 if ($objecttmp->element ==
'expensereport') {
180 $thirdparty =
new User($db);
181 } elseif ($objecttmp->element ==
'contact') {
182 $thirdparty =
new Contact($db);
183 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
185 } elseif ($objecttmp->element ==
'holiday') {
186 $thirdparty =
new User($db);
187 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
191 foreach ($toselect as $toselectid) {
192 $objecttmp =
new $objectclass($db);
193 '@phan-var-force CommonObject $objecttmp';
195 $result = $objecttmp->fetch($toselectid);
197 $listofobjectid[$toselectid] = $toselectid;
200 $tmpobjectid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
201 if ($objecttmp->element ==
'societe') {
202 '@phan-var-force Societe $objecttmp';
204 $tmpobjectid = $objecttmp->id;
205 } elseif ($objecttmp->element ==
'contact') {
206 '@phan-var-force Contact $objecttmp';
208 $tmpobjectid = $objecttmp->id;
209 } elseif ($objecttmp->element ==
'expensereport') {
210 '@phan-var-force ExpenseReport $objecttmp';
212 $tmpobjectid = $objecttmp->fk_user_author;
213 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
214 '@phan-var-force Partnership $objecttmp';
216 $tmpobjectid = $objecttmp->fk_member;
217 } elseif ($objecttmp->element ==
'holiday') {
218 '@phan-var-force Holiday $objecttmp';
220 $tmpobjectid = $objecttmp->fk_user;
221 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
222 '@phan-var-force ConferenceOrBoothAttendee $objecttmp';
224 $tmpobjectid = $objecttmp->id;
226 if (empty($tmpobjectid)) {
230 if ($objectclass ==
'Facture') {
231 '@phan-var-force Facture $objecttmp';
233 $tmparraycontact = array();
234 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'BILLING');
235 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
236 foreach ($tmparraycontact as $data_email) {
237 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
240 } elseif ($objectclass ==
'CommandeFournisseur') {
241 '@phan-var-force CommandeFournisseur $objecttmp';
243 $tmparraycontact = array();
244 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'CUSTOMER');
245 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
246 foreach ($tmparraycontact as $data_email) {
247 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
252 $listofobjectthirdparties[$tmpobjectid] = $tmpobjectid;
253 $listofobjectref[$tmpobjectid][$toselectid] = $objecttmp;
259 if (
GETPOST(
'fromtype',
'alpha') ===
'user' && empty($user->email)) {
261 setEventMessages($langs->trans(
"NoSenderEmailDefined"),
null,
'warnings');
262 $massaction =
'presend';
265 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
266 if (!is_array($receiver)) {
267 if (empty($receiver) || $receiver ==
'-1') {
270 $receiver = array($receiver);
273 if (!trim(
GETPOST(
'sendto',
'alphawithlgt')) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) {
275 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailRecipient")),
null,
'warnings');
276 $massaction =
'presend';
279 if (!
GETPOST(
'subject',
'restricthtml')) {
281 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTopic")),
null,
'warnings');
282 $massaction =
'presend';
287 foreach ($listofobjectthirdparties as $thirdpartyid) {
288 $result = $thirdparty->fetch($thirdpartyid);
290 dol_print_error($db);
301 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
303 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
305 if (count($receiver) > 0 && is_object($thirdparty)) {
306 foreach ($receiver as $key => $val) {
308 if ($val ==
'thirdparty') {
309 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
310 } elseif ($val && method_exists($thirdparty,
'contact_get_property')) {
311 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
316 $sendto = implode(
',', $tmparray);
319 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
320 if (!is_array($receivercc)) {
321 if ($receivercc ==
'-1') {
322 $receivercc = array();
324 $receivercc = array($receivercc);
328 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
329 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
331 if (count($receivercc) > 0) {
332 foreach ($receivercc as $key => $val) {
334 if ($val ==
'thirdparty') {
335 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
337 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
342 $sendtocc = implode(
',', $tmparray);
345 $listofqualifiedobj = array();
346 $listofqualifiedref = array();
347 $thirdpartywithoutemail = array();
349 foreach ($listofobjectref[$thirdpartyid] as $objectid => $objectobj) {
356 $langs->load(
"errors");
358 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyProposalNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
362 $langs->load(
"errors");
364 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyOrderNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
368 $langs->load(
"errors");
370 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyInvoiceValidatedCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
375 if (empty($sendto)) {
376 if ($objectobj->element ==
'societe') {
377 $sendto = $objectobj->email;
378 } elseif ($objectobj->element ==
'expensereport') {
379 $fuser =
new User($db);
380 $fuser->fetch($objectobj->fk_user_author);
381 $sendto = $fuser->email;
382 } elseif ($objectobj->element ==
'contact') {
384 $fcontact->fetch($objectobj->id);
385 $sendto = $fcontact->email;
386 } elseif ($objectobj->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
388 $fadherent->fetch($objectobj->fk_member);
389 $sendto = $fadherent->email;
390 } elseif ($objectobj->element ==
'holiday') {
391 $fuser =
new User($db);
392 $fuser->fetch($objectobj->fk_user);
393 $sendto = $fuser->email;
394 } elseif ($objectobj->element ==
'facture' && !empty($listofobjectcontacts[$objectid])) {
395 $emails_to_sends = array();
396 $objectobj->fetch_thirdparty();
397 $contactidtosend = array();
398 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
399 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
400 if (!in_array($contactemailid, $contactidtosend)) {
401 $contactidtosend[] = $contactemailid;
404 if (count($emails_to_sends) > 0) {
405 $sendto = implode(
',', $emails_to_sends);
407 } elseif ($objectobj->element ==
'order_supplier' && !empty($listofobjectcontacts[$objectid])) {
408 $emails_to_sends = array();
409 $objectobj->fetch_thirdparty();
410 $contactidtosend = array();
411 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
412 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
413 if (!in_array($contactemailid, $contactidtosend)) {
414 $contactidtosend[] = $contactemailid;
417 if (count($emails_to_sends) > 0) {
418 $sendto = implode(
',', $emails_to_sends);
420 } elseif ($objectobj->element ==
'conferenceorboothattendee') {
421 $sendto = $objectobj->email;
423 $objectobj->fetch_thirdparty();
424 $sendto = $objectobj->thirdparty->email;
428 if (empty($sendto)) {
429 if ($objectobj->element ==
'societe') {
431 $objectobj->thirdparty = $objectobj;
436 if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id])) {
437 $resaction .=
'<div class="error">'.$langs->trans(
'NoRecipientEmail', $objectobj->thirdparty->name).
'</div><br>';
439 dol_syslog(
'No recipient for thirdparty: '.$objectobj->thirdparty->name, LOG_WARNING);
440 $thirdpartywithoutemail[$objectobj->thirdparty->id] = 1;
444 if (
GETPOST(
'addmaindocfile')) {
451 $filedir = $uploaddir.
'/'.$subdir.dol_sanitizeFileName($objectobj->ref);
452 $filepath = $filedir.
'/'.$filename;
455 if ($objectobj->element ==
'invoice_supplier') {
456 $fileparams =
dol_most_recent_file($uploaddir.
'/'.
get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element).$objectobj->ref, preg_quote($objectobj->ref,
'/').
'([^\-])+');
457 $filepath = $fileparams[
'fullname'];
460 if (
getDolGlobalInt(
'MAIL_MASS_ACTION_SEARCH_MOST_RECENT_FILE_IF_NOT_FOUND') && isset($filepath) && !
dol_is_file($filepath)) {
462 if (isset($fileparams)) {
463 $filepath = $fileparams[
'fullname'];
464 $filename = $fileparams[
'name'];
469 $filename_found =
'';
470 $filepath_found =
'';
471 $file_check_list = array();
472 $file_check_list[] = array(
476 if (
getDolGlobalString(
'MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND') && !empty($objectobj->last_main_doc)) {
477 $file_check_list[] = array(
478 'name' => basename($objectobj->last_main_doc),
479 'path' => DOL_DATA_ROOT .
'/' . $objectobj->last_main_doc,
482 foreach ($file_check_list as $file_check_arr) {
484 $filename_found = $file_check_arr[
'name'];
485 $filepath_found = $file_check_arr[
'path'];
490 if ($filepath_found) {
492 $attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array(
493 'paths' => array($filepath_found),
494 'names' => array($filename_found),
499 $langs->load(
"errors");
500 foreach ($file_check_list as $file_check_arr) {
501 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorCantReadFile', $file_check_arr[
'path']).
'</div><br>';
502 dol_syslog(
'Failed to read file: '.$file_check_arr[
'path'], LOG_WARNING);
509 $listofqualifiedobj[$objectid] = $objectobj;
510 $listofqualifiedref[$objectid] = $objectobj->ref;
517 if (count($listofqualifiedobj) > 0) {
518 $langs->load(
"commercial");
522 $fromtype =
GETPOST(
'fromtype');
523 if ($fromtype ===
'user') {
524 $email_from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
525 } elseif ($fromtype ===
'company') {
527 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
529 $email_from = trim($tmp[((
int) $reg[1] - 1)]);
530 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
531 $sql =
"SELECT rowid, label, email FROM ".MAIN_DB_PREFIX.
"c_email_senderprofile WHERE rowid = ".(int) $reg[1];
532 $resql = $db->query($sql);
533 $obj = $db->fetch_object($resql);
541 $replyto = $email_from;
542 $subject =
GETPOST(
'subject',
'restricthtml');
543 $message =
GETPOST(
'message',
'restricthtml');
545 $sendtobcc =
GETPOST(
'sendtoccc');
546 if ($objectclass ==
'Propal') {
549 if ($objectclass ==
'Commande') {
552 if ($objectclass ==
'Facture') {
555 if ($objectclass ==
'SupplierProposal') {
556 $sendtobcc .= (!
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO') ?
'' : (($sendtobcc ?
", " :
"") .
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO')));
558 if ($objectclass ==
'CommandeFournisseur') {
561 if ($objectclass ==
'FactureFournisseur') {
564 if ($objectclass ==
'Project') {
570 $looparray = array();
571 if (!$oneemailperrecipient) {
572 $looparray = $listofqualifiedobj;
573 foreach ($looparray as $key => $objecttmp) {
574 $looparray[$key]->thirdparty = $thirdparty;
577 $objectforloop =
new $objectclass($db);
578 $objectforloop->thirdparty = $thirdparty;
579 $looparray[0] = $objectforloop;
582 dol_syslog(
"We have set an array of ".count($looparray).
" emails to send. oneemailperrecipient=".$oneemailperrecipient);
584 foreach ($looparray as $objectid => $objecttmp) {
586 if (
isModEnabled(
'project') && method_exists($objecttmp,
'fetchProject') && is_null($objecttmp->project)) {
587 $objecttmp->fetchProject();
589 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null, $objecttmp);
590 $substitutionarray[
'__ID__'] = ($oneemailperrecipient ? implode(
', ', array_keys($listofqualifiedobj)) : $objecttmp->id);
591 $substitutionarray[
'__REF__'] = ($oneemailperrecipient ? implode(
', ', $listofqualifiedref) : $objecttmp->
ref);
592 $substitutionarray[
'__EMAIL__'] = $thirdparty->email;
593 $substitutionarray[
'__CHECK_READ__'] =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag=undefined&securitykey='.
dol_hash(
getDolGlobalString(
'MAILING_EMAIL_UNSUBSCRIBE_KEY').
"-undefined",
'md5').
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
595 if ($oneemailperrecipient) {
596 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'';
597 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
600 $parameters = array(
'mode' =>
'formemail');
602 if (!empty($listofobjectthirdparties)) {
603 $parameters[
'listofobjectthirdparties'] = $listofobjectthirdparties;
605 if (!empty($listofobjectref)) {
606 $parameters[
'listofobjectref'] = $listofobjectref;
614 $attachedfiles = array(
'paths' => array(),
'names' => array(),
'mimes' => array());
615 if ($oneemailperrecipient) {
617 if (is_array($attachedfilesThirdpartyObj[$thirdparty->id]) && count($attachedfilesThirdpartyObj[$thirdparty->id])) {
618 foreach ($attachedfilesThirdpartyObj[$thirdparty->id] as $keyObjId => $objAttachedFiles) {
620 $attachedfiles = array(
621 'paths' => array_merge($attachedfiles[
'paths'], $objAttachedFiles[
'paths']),
622 'names' => array_merge($attachedfiles[
'names'], $objAttachedFiles[
'names']),
623 'mimes' => array_merge($attachedfiles[
'mimes'], $objAttachedFiles[
'mimes'])
627 } elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) {
630 $attachedfiles = $attachedfilesThirdpartyObj[$thirdparty->id][$objectid];
633 $filepath = $attachedfiles[
'paths'];
634 $filename = $attachedfiles[
'names'];
635 $mimetype = $attachedfiles[
'mimes'];
638 if ($oneemailperrecipient) {
639 $trackid =
'thi'.$thirdparty->id;
640 if ($objecttmp->element ==
'expensereport') {
641 $trackid =
'use'.$thirdparty->id;
642 } elseif ($objecttmp->element ==
'contact') {
643 $trackid =
'ctc'.$thirdparty->id;
644 } elseif ($objecttmp->element ==
'holiday') {
645 $trackid =
'use'.$thirdparty->id;
648 $trackid = strtolower(get_class($objecttmp));
649 if (get_class($objecttmp) ==
'Contact') {
651 } elseif (get_class($objecttmp) ==
'Contrat') {
653 } elseif (get_class($objecttmp) ==
'Propal') {
655 } elseif (get_class($objecttmp) ==
'Commande') {
657 } elseif (get_class($objecttmp) ==
'Facture') {
659 } elseif (get_class($objecttmp) ==
'SupplierProposal') {
661 } elseif (get_class($objecttmp) ==
'CommandeFournisseur') {
663 } elseif (get_class($objecttmp) ==
'FactureFournisseur') {
667 $trackid .= $objecttmp->id;
673 if (empty($sendcontext)) {
674 $sendcontext =
'standard';
678 $vardir =
$conf->user->dir_output.
"/".$user->id;
679 $upload_dir_tmp = $vardir.
'/temp';
682 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
683 $mailfile =
new CMailFile($subjectreplaced, (
string) $sendto, $email_from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, (
int) $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext,
'', $upload_dir_tmp);
684 if ($mailfile->error) {
685 $resaction .=
'<div class="error">'.$mailfile->error.
'</div>';
687 $result = $mailfile->sendfile();
689 $resaction .= $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($mailfile->addr_from, 2), $mailfile->getValidAddress($mailfile->addr_to, 2)).
'<br>';
694 foreach ($listofqualifiedobj as $objid2 => $objectobj2) {
695 if ((!$oneemailperrecipient) && $objid2 != $objectid) {
699 dol_syslog(
"Try to insert email event into agenda for objid=".$objid2.
" => objectobj=".get_class($objectobj2));
708 $actionmsg = $langs->transnoentities(
'MailSentByTo', $email_from, (
string) $sendto);
711 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'Bcc').
": ".$sendtocc);
713 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'MailTopic').
": ".$subjectreplaced);
714 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'TextUsedInTheMessageBody').
":");
720 $objectobj2->sendtoid = (empty($contactidtosend) ? 0 : $contactidtosend);
721 $objectobj2->actionmsg = $actionmsg;
722 $objectobj2->actionmsg2 = $actionmsg2;
723 $objectobj2->fk_element = $objid2;
724 $objectobj2->elementtype = $objectobj2->element;
726 $objectobj2->actionmsg2 = $subjectreplaced;
729 $triggername = strtoupper(get_class($objectobj2)).
'_SENTBYMAIL';
730 if ($triggername ==
'SOCIETE_SENTBYMAIL') {
731 $triggername =
'COMPANY_SENTBYMAIL';
733 if ($triggername ==
'CONTRAT_SENTBYMAIL') {
734 $triggername =
'CONTRACT_SENTBYMAIL';
736 if ($triggername ==
'COMMANDE_SENTBYMAIL') {
737 $triggername =
'ORDER_SENTBYMAIL';
739 if ($triggername ==
'FACTURE_SENTBYMAIL') {
740 $triggername =
'BILL_SENTBYMAIL';
742 if ($triggername ==
'EXPEDITION_SENTBYMAIL') {
743 $triggername =
'SHIPPING_SENTBYMAIL';
745 if ($triggername ==
'COMMANDEFOURNISSEUR_SENTBYMAIL') {
746 $triggername =
'ORDER_SUPPLIER_SENTBYMAIL';
748 if ($triggername ==
'FACTUREFOURNISSEUR_SENTBYMAIL') {
749 $triggername =
'BILL_SUPPLIER_SENTBYMAIL';
751 if ($triggername ==
'SUPPLIERPROPOSAL_SENTBYMAIL') {
752 $triggername =
'PROPOSAL_SUPPLIER_SENTBYMAIL';
754 if ($triggername ==
'PROJET_SENTBYMAIL') {
755 $triggername =
'PROJECT_SENTBYMAIL';
758 if (!empty($triggername)) {
760 $result = $objectobj2->call_trigger($triggername, $user);
767 setEventMessages($db->lasterror(),
null,
'errors');
768 dol_syslog(
"Error in trigger ".$triggername.
' '.$db->lasterror(), LOG_ERR);
775 $langs->load(
"other");
776 if ($mailfile->error) {
777 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $email_from, (
string) $sendto);
778 $resaction .=
'<br><div class="error">'.$mailfile->error.
'</div>';
780 $resaction .=
'<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
782 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $email_from, (
string) $sendto) .
'<br><div class="error">(unhandled error)</div>';
790 $resaction .= ($resaction ?
'<br>' : $resaction);
791 $resaction .=
'<strong>'.$langs->trans(
"ResultOfMailSending").
':</strong><br>'.
"\n";
792 $resaction .= $langs->trans(
"NbSelected").
': '.count($toselect).
"\n<br>";
793 $resaction .= $langs->trans(
"NbIgnored").
': '.($nbignored ? $nbignored : 0).
"\n<br>";
794 $resaction .= $langs->trans(
"NbSent").
': '.($nbsent ? $nbsent : 0).
"\n<br>";
799 setEventMessages($langs->trans(
"EMailSentForNElements", $nbsent.
'/'.count($toselect)),
null,
'mesgs');
800 setEventMessages($resaction,
null,
'mesgs');
803 setEventMessages($resaction,
null,
'warnings');
812if (!$error && $massaction ==
'cancelorders') {
817 $orders =
GETPOST(
'toselect',
'array:int');
818 foreach ($orders as $id_order) {
820 if ($cmd->fetch($id_order) <= 0) {
825 $langs->load(
'errors');
826 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref),
null,
'errors');
831 $result = $cmd->cancel($user);
835 setEventMessages($cmd->error, $cmd->errors,
'errors');
843 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null,
'mesgs');
851if (!$error && $massaction ==
"builddoc" && $permissiontoread && !
GETPOST(
'button_search')) {
852 if (empty($diroutputmassaction)) {
853 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
857 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
858 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
859 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
861 $objecttmp =
new $objectclass($db);
862 $listofobjectid = array();
863 $listofobjectthirdparties = array();
864 $listofobjectref = array();
865 foreach ($toselect as $toselectid) {
866 $objecttmp =
new $objectclass($db);
867 $result = $objecttmp->fetch($toselectid);
869 $listofobjectid[$toselectid] = $toselectid;
870 $thirdpartyid = !empty($objecttmp->fk_soc) ? $objecttmp->fk_soc : $objecttmp->socid;
871 $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid;
872 $listofobjectref[$toselectid] = $objecttmp->ref;
876 $arrayofinclusion = array();
878 'listofobjectref' => $listofobjectref,
879 'arrayofinclusion' => &$arrayofinclusion,
881 $reshook = $hookmanager->executeHooks(
'updateSearchRegexToMergeDoc', $parameters,
$object, $action);
883 if (empty($reshook)) {
884 foreach ($listofobjectref as $tmppdf) {
887 foreach ($listofobjectref as $tmppdf) {
888 $arrayofinclusion[] =
'^'.preg_quote(
dol_sanitizeFileName($tmppdf),
'/').
'_[\w\-\'\&\.]+\.pdf$';
892 $listoffiles =
dol_dir_list($uploaddir,
'all', 1, $arrayofinclusion,
'\.meta$|\.png$',
'date', SORT_DESC, 0, 1);
894 dol_syslog(
"Found ".count($listoffiles).
" files");
899 foreach ($listofobjectref as $basename) {
901 foreach ($listoffiles as $filefound) {
902 if (strstr($filefound[
"name"], $basename)) {
903 $files[] = $filefound[
'fullname'];
910 $outputlangs = $langs;
913 $newlang =
GETPOST(
'lang_id',
'aZ09');
918 if (!empty($newlang)) {
920 $outputlangs->setDefaultLang($newlang);
929 $filename = preg_replace(
'/\s/',
'_', $filename);
932 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status == $objecttmp::STATUS_VALIDATED) {
933 if ($option ==
'late') {
940 $filename .=
'_'.$year;
943 $filename .=
'_'.$month;
946 if (count($files) > 0) {
948 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
951 foreach ($files as $f) {
952 $input_files .=
' '.escapeshellarg($f);
955 $cmd =
'pdftk '.$input_files.
' cat output '.escapeshellarg($file);
959 if (file_exists($file)) {
962 $langs->load(
"exports");
963 setEventMessages($langs->trans(
'FileSuccessfullyBuilt', $filename.
'_'.
dol_print_date($now,
'dayhourlog')),
null,
'mesgs');
965 setEventMessages($langs->trans(
'ErrorPDFTkOutputFileNotFound'),
null,
'errors');
968 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
973 $page_largeur = $formatarray[
'width'];
974 $page_hauteur = $formatarray[
'height'];
975 $format = array($page_largeur, $page_hauteur);
979 if (class_exists(
'TCPDF')) {
980 $pdf->setPrintHeader(
false);
981 $pdf->setPrintFooter(
false);
986 $pdf->SetCompression(
false);
991 foreach ($files as $file) {
993 $pagecount = $pdf->setSourceFile($file);
994 for ($i = 1; $i <= $pagecount; $i++) {
995 $tplidx = $pdf->importPage($i);
996 $s = $pdf->getTemplatesize($tplidx);
997 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
998 $pdf->useTemplate($tplidx);
1007 $filename = preg_replace(
'/\s/',
'_', $filename);
1011 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status == $objecttmp::STATUS_VALIDATED) {
1012 if ($option ==
'late') {
1018 if (!empty($year)) {
1019 $filename .=
'_'.$year;
1021 if (!empty($month)) {
1022 $filename .=
'_'.$month;
1026 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
1027 $pdf->Output($file,
'F');
1030 $langs->load(
"exports");
1031 setEventMessages($langs->trans(
'FileSuccessfullyBuilt', $filename.
'_'.
dol_print_date($now,
'dayhourlog')),
null,
'mesgs');
1033 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
1039if ($action ==
'remove_file') {
1040 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1042 $langs->load(
"other");
1043 $upload_dir = $diroutputmassaction;
1044 $file = $upload_dir.
'/'.
GETPOST(
'file');
1047 setEventMessages($langs->trans(
"FileWasRemoved",
GETPOST(
'file')),
null,
'mesgs');
1049 setEventMessages($langs->trans(
"ErrorFailToDeleteFile",
GETPOST(
'file')),
null,
'errors');
1056if (!$error && $massaction ==
'validate' && $permissiontoadd) {
1057 $objecttmp =
new $objectclass($db);
1059 if (($objecttmp->element ==
'facture' || $objecttmp->element ==
'invoice') &&
isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL')) {
1060 $langs->load(
"errors");
1061 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
1065 $langs->load(
"errors");
1066 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
1069 if ($objecttmp->element ==
'facture') {
1072 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
1073 $sql .=
" WHERE rowid IN (".$db->sanitize(implode(
",", $toselect)).
")";
1074 $sql .=
" ORDER BY datef";
1076 $resql = $db->query($sql);
1079 while (!empty($arr = $db->fetch_row($resql))) {
1080 $toselectnew[] = $arr[0];
1082 $toselect = (empty($toselectnew)) ? $toselect : $toselectnew;
1084 dol_print_error($db);
1096 $perrecordtransaction = (int)
getDolGlobalInt(
'MAIN_MASSVALIDATE_'.strtoupper($objectclass).
'_NO_GLOBAL_TRANSACTION');
1097 if (!$perrecordtransaction) {
1102 foreach ($toselect as $toselectid) {
1103 if ($perrecordtransaction) {
1106 $result = $objecttmp->fetch($toselectid);
1108 if (method_exists($objecttmp,
'validate')) {
1109 $result = $objecttmp->validate($user);
1110 } elseif (method_exists($objecttmp,
'setValid')) {
1111 $result = $objecttmp->setValid($user);
1113 $objecttmp->error =
'No method validate or setValid on this object';
1117 $langs->load(
"errors");
1118 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref),
null,
'errors');
1120 if ($perrecordtransaction) {
1124 } elseif ($result < 0) {
1125 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1127 if ($perrecordtransaction) {
1135 $outputlangs = $langs;
1138 $newlang =
GETPOST(
'lang_id',
'aZ09');
1140 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && property_exists($objecttmp,
'thirdparty')) {
1141 if ((property_exists($objecttmp,
'socid') || property_exists($objecttmp,
'fk_soc')) && empty($objecttmp->thirdparty)) {
1142 $objecttmp->fetch_thirdparty();
1144 if (!empty($objecttmp->thirdparty)) {
1145 $newlang = $objecttmp->thirdparty->default_lang;
1148 if (!empty($newlang)) {
1150 $outputlangs->setDefaultLang($newlang);
1151 $outputlangs->load(
'products');
1153 $model = $objecttmp->model_pdf;
1154 $ret = $objecttmp->fetch($objecttmp->id);
1157 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
1158 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
1159 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
1160 $moreparams = isset($moreparams) ? $moreparams :
null;
1162 $result = $objecttmp->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1164 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1168 if ($perrecordtransaction) {
1173 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1175 if ($perrecordtransaction) {
1184 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null,
'mesgs');
1186 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
1188 if (!$perrecordtransaction) {
1191 } elseif (!$perrecordtransaction) {
1198if (!$error && ($massaction ==
'delete' || ($action ==
'delete' && $confirm ==
'yes')) && $permissiontodelete) {
1201 $objecttmp =
new $objectclass($db);
1208 $unique_arr = array_unique($toselect);
1209 foreach ($unique_arr as $toselectid) {
1210 $result = $objecttmp->fetch($toselectid);
1214 $langs->load(
"errors");
1216 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).
'</div><br>';
1220 if (method_exists($objecttmp,
'is_erasable') && $objecttmp->is_erasable() <= 0) {
1221 $langs->load(
"errors");
1223 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorRecordHasChildren').
' '.$objecttmp->ref.
'</div><br>';
1228 $langs->load(
"errors");
1230 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorLeaveRequestMustBeDraftCanceledOrRefusedToBeDeleted', $objecttmp->ref).
'</div><br>';
1234 if ($objectclass ==
"Task" && $objecttmp->hasChildren() > 0) {
1235 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".((int) $objecttmp->id);
1236 $res = $db->query($sql);
1239 setEventMessage(
'ErrorRecordParentingNotModified',
'errors');
1244 if ($objecttmp->element ==
'societe') {
1246 '@phan-var-force Societe $objecttmp';
1248 $result = $objecttmp->delete($objecttmp->id, $user, 1);
1250 $objecttmp->oldcopy =
dol_clone($objecttmp);
1251 $result = $objecttmp->delete($user);
1254 if (empty($result)) {
1255 $TMsg = array_merge($objecttmp->errors, $TMsg);
1256 } elseif ($result < 0) {
1257 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1264 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1270 if (empty($error)) {
1273 setEventMessages($langs->trans(
"RecordsDeleted", $nbok),
null,
'mesgs');
1274 } elseif ($nbok > 0) {
1275 setEventMessages($langs->trans(
"RecordDeleted", $nbok),
null,
'mesgs');
1277 setEventMessages($langs->trans(
"NoRecordDeleted"),
null,
'mesgs');
1281 if (!empty($TMsg)) {
1283 setEventMessages(
'', array_unique($TMsg),
'warnings');
1294if (!$error && $massaction ==
'generate_doc' && $permissiontoread) {
1297@phan-var-force
'Commande'|
'CommandeFournisseur'|
'Contrat'|
'Expedition'|
'ExpenseReport'|
'Facture'|
'FactureFournisseur'|
'Fichinter'|
'Project'|
'Propal'|
'SupplierProposal' $objectclass
1303 $objecttmp =
new $objectclass($db);
1305 foreach ($toselect as $toselectid) {
1306 $objecttmp->thirdparty =
null;
1307 $result = $objecttmp->fetch($toselectid);
1310 $outputlangs = $langs;
1314 $newlang =
GETPOST(
'lang_id',
'aZ09');
1316 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) {
1317 $newlang = $objecttmp->thirdparty->default_lang;
1319 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->default_lang)) {
1320 $newlang = $objecttmp->default_lang;
1322 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && empty($objecttmp->thirdparty)) {
1323 $objecttmp->fetch_thirdparty();
1324 $newlang = $objecttmp->thirdparty->default_lang;
1326 if (!empty($newlang)) {
1328 $outputlangs->setDefaultLang($newlang);
1332 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
1333 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
1334 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
1335 $moreparams = isset($moreparams) ? $moreparams :
null;
1337 $result = $objecttmp->generateDocument($objecttmp->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1340 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1347 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1355 setEventMessages($langs->trans(
"RecordsGenerated", $nbok),
null,
'mesgs');
1357 setEventMessages($langs->trans(
"RecordGenerated", $nbok),
null,
'mesgs');
1365if (!$error && ($action ==
'affecttag' && $confirm ==
'yes') && $permissiontoadd) {
1369 $affecttag_type =
GETPOST(
'affecttag_type',
'alpha');
1370 if (!empty($affecttag_type)) {
1371 $affecttag_type_array = explode(
',', $affecttag_type);
1373 setEventMessage(
'CategTypeNotFound',
'errors');
1375 if (!empty($affecttag_type_array)) {
1377 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1379 $to_affecttag_type_array = array();
1380 $categ_type_array = $categ->getMapList();
1381 foreach ($categ_type_array as $categdef) {
1382 if (in_array($categdef[
'code'], $affecttag_type_array)) {
1383 $to_affecttag_type_array[] = $categdef[
'code'];
1388 if (!empty($to_affecttag_type_array)) {
1391 '@phan-var-force CommonObject $object';
1392 foreach ($to_affecttag_type_array as $categ_type) {
1393 $contcats =
GETPOST(
'contcats_' . $categ_type,
'array');
1394 foreach ($toselect as $toselectid) {
1395 $result =
$object->fetch($toselectid);
1397 $result =
$object->setCategoriesCommon($contcats, $categ_type,
false);
1414 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null);
1416 $toselect = array();
1422if (!$error && ($action ==
'updateprice' && $confirm ==
'yes') && $permissiontoadd) {
1423 '@phan-var-force Product|ProductCustomerPrice $obj';
1424 '@phan-var-force Product|ProductCustomerPrice $object';
1429 if ($pricepercentage == 0) {
1430 setEventMessages($langs->trans(
"RecordsModified", 0),
null);
1432 foreach ($toselect as $toselectid) {
1433 $result =
$object->fetch($toselectid);
1437 if (
$object->price_base_type ==
'TTC') {
1438 $newprice =
$object->price_ttc * (100 + $pricepercentage) / 100;
1439 $minprice =
$object->price_min_ttc;
1441 $newprice =
$object->price * (100 + $pricepercentage) / 100;
1442 $minprice =
$object->price_min;
1444 $res =
$object->updatePrice($newprice,
$object->price_base_type, $user,
$object->tva_tx, $minprice, 0,
$object->tva_npr, 0, 0, array(),
$object->default_vat_code);
1452 for ($level = 1; $level <= $maxlevel; $level++) {
1453 if (
$object->price_base_type ==
'TTC') {
1454 $newprice =
$object->multiprices_ttc[$level] * (100 + $pricepercentage) / 100;
1455 $minprice =
$object->multiprices_min_ttc[$level];
1457 $newprice =
$object->multiprices[$level] * (100 + $pricepercentage) / 100;
1458 $minprice =
$object->multiprices_min[$level];
1460 $res =
$object->updatePrice($newprice,
$object->price_base_type, $user,
$object->tva_tx, $minprice, $level,
$object->tva_npr, 0, 0, array(),
$object->default_vat_code);
1477 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null);
1480 $toselect = array();
1486if (!$error && ($action ==
'setsupervisor' && $confirm ==
'yes') && $permissiontoadd) {
1487 '@phan-var-force User $object';
1490 $supervisortoset =
GETPOSTINT(
'supervisortoset');
1491 if (!empty($supervisortoset)) {
1492 foreach ($toselect as $toselectid) {
1493 $result =
$object->fetch($toselectid);
1495 $object->fk_user = $supervisortoset;
1496 $res =
$object->update($user);
1509 setEventMessage(
'UserNotFound',
'errors');
1514 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null);
1516 $toselect = array();
1522if (!$error && ($action ==
'affectuser' && $confirm ==
'yes') && $permissiontoadd) {
1527 $projectrole =
GETPOST(
'projectrole');
1528 $tasksrole =
GETPOST(
'tasksrole');
1529 if (!empty($usertoaffect)) {
1530 foreach ($toselect as $toselectid) {
1531 $result =
$object->fetch($toselectid);
1533 $res =
$object->add_contact($usertoaffect, $projectrole,
'internal');
1535 $taskstatic =
new Task($db);
1536 $task_array = $taskstatic->getTasksArray(
null,
null,
$object->id, 0, 0);
1538 foreach ($task_array as $task) {
1539 $tasksToAffect =
new Task($db);
1540 $result = $tasksToAffect->fetch($task->id);
1542 $res = $tasksToAffect->add_contact($usertoaffect, $tasksrole,
'internal');
1544 setEventMessages($tasksToAffect->error, $tasksToAffect->errors,
'errors');
1559 setEventMessage(
'UserNotFound',
'errors');
1564 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null);
1566 $toselect = array();
1572if (!$error && ($massaction ==
'enable' || ($action ==
'enable' && $confirm ==
'yes')) && $permissiontoadd) {
1575 $objecttmp =
new $objectclass($db);
1577 foreach ($toselect as $toselectid) {
1578 $result = $objecttmp->fetch($toselectid);
1580 if (in_array($objecttmp->element, array(
'societe'))) {
1581 $result = $objecttmp->setStatut(1);
1584 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1591 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1599 setEventMessages($langs->trans(
"RecordsEnabled", $nbok),
null,
'mesgs');
1601 setEventMessages($langs->trans(
"RecordEnabled"),
null,
'mesgs');
1609if (!$error && ($massaction ==
'disable' || ($action ==
'disable' && $confirm ==
'yes')) && $permissiontoadd) {
1612 $objecttmp =
new $objectclass($db);
1614 foreach ($toselect as $toselectid) {
1615 $result = $objecttmp->fetch($toselectid);
1617 if (in_array($objecttmp->element, array(
'societe'))) {
1618 $result = $objecttmp->setStatut(0);
1621 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1628 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1636 setEventMessages($langs->trans(
"RecordsDisabled", $nbok),
null,
'mesgs');
1638 setEventMessages($langs->trans(
"RecordDisabled"),
null,
'mesgs');
1646if (!$error && $action ==
'confirm_edit_value_extrafields' && $confirm ==
'yes' && $permissiontoadd) {
1649 $objecttmp =
new $objectclass($db);
1651 $e->fetch_name_optionals_label($objecttmp->table_element);
1654 $extrafieldKeyToUpdate =
GETPOST(
'extrafield-key-to-update');
1657 foreach ($toselect as $toselectid) {
1659 $objecttmp =
new $objectclass($db);
1660 $result = $objecttmp->fetch($toselectid);
1663 $ret = $e->setOptionalsFromPost(
null, $objecttmp, $extrafieldKeyToUpdate);
1665 $objecttmp->insertExtraFields();
1669 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1672 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1680 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null,
'mesgs');
1681 } elseif ($nbok == 1) {
1682 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
1690if (!$error && ($massaction ==
'assignsalerepresentative' || ($action ==
'assignsalerepresentative' && $confirm ==
'yes')) && $permissiontoadd) {
1693 $objecttmp =
new $objectclass($db);
1696 foreach ($toselect as $toselectid) {
1697 $result = $objecttmp->fetch($toselectid);
1699 if (in_array($objecttmp->element, array(
'societe'))) {
1700 $result = $objecttmp->setSalesRep(
GETPOST(
"commercial",
"alpha"));
1703 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1710 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1718 setEventMessages($langs->trans(
"CommercialsAffected", $nbok),
null,
'mesgs');
1720 setEventMessages($langs->trans(
"CommercialAffected"),
null,
'mesgs');
1728if (!$error && ($massaction ==
'unassigncommercial' || ($action ==
'unassigncommercial' && $confirm ==
'yes')) && $permissiontoadd) {
1731 $objecttmp =
new $objectclass($db);
1734 foreach ($toselect as $toselectid) {
1735 $result = $objecttmp->fetch($toselectid);
1737 if (in_array($objecttmp->element, array(
'societe'))) {
1738 $TCommercial =
GETPOST(
"commercial",
"alpha");
1739 if (is_array($TCommercial)) {
1740 foreach ($TCommercial as $commercial) {
1741 $result = $objecttmp->del_commercial($user, $commercial);
1746 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1753 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1761 setEventMessages($langs->trans(
"CommercialsDisaffected", $nbok),
null,
'mesgs');
1763 setEventMessages($langs->trans(
"CommercialDisaffected"),
null,
'mesgs');
1771if (!$error && ($massaction ==
'approveleave' || ($action ==
'approveleave' && $confirm ==
'yes')) && $permissiontoapprove) {
1774 $objecttmp =
new $objectclass($db);
1775 '@phan-var-force Holiday $objecttmp';
1777 foreach ($toselect as $toselectid) {
1778 $result = $objecttmp->fetch($toselectid);
1781 setEventMessages($langs->trans(
'StatusOfRefMustBe', $objecttmp->ref, $langs->transnoentitiesnoconv(
'Validated')),
null,
'warnings');
1784 if ($user->id == $objecttmp->fk_validator) {
1785 $objecttmp->oldcopy =
dol_clone($objecttmp, 2);
1787 $objecttmp->date_valid =
dol_now();
1788 $objecttmp->fk_user_valid = $user->id;
1789 $objecttmp->date_approval =
dol_now();
1790 $objecttmp->fk_user_approve = $user->id;
1792 $objecttmp->statut = $objecttmp->status;
1794 $verif = $objecttmp->approve($user);
1797 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1805 $tmpUser =
new User($db);
1806 $result = $tmpUser->fetch($objecttmp->fk_user);
1809 $nbopenedday =
num_open_day($objecttmp->date_debut_gmt, $objecttmp->date_fin_gmt, 0, 1, $objecttmp->halfday, $tmpUser->country_id);
1810 $soldeActuel = $objecttmp->getCpforUser($objecttmp->fk_user, $objecttmp->fk_type);
1811 $newSolde = ($soldeActuel - $nbopenedday);
1814 $result = $objecttmp->addLogCP($user->id, $objecttmp->fk_user, $langs->transnoentitiesnoconv(
"Holidays"), $newSolde, $objecttmp->fk_type);
1817 setEventMessages(
null, $objecttmp->errors,
'errors');
1821 $result = $objecttmp->updateSoldeCP($objecttmp->fk_user, $newSolde, $objecttmp->fk_type);
1824 setEventMessages(
null, $objecttmp->errors,
'errors');
1830 $destinataire =
new User($db);
1831 $destinataire->fetch($objecttmp->fk_user);
1832 $emailTo = $destinataire->email;
1835 dol_syslog(
"User that request leave has no email, so we redirect directly to finished page without sending email");
1838 $expediteur =
new User($db);
1839 $expediteur->fetch($objecttmp->fk_validator);
1849 $subject = $societeName.
" - ".$langs->transnoentitiesnoconv(
"HolidaysValidated");
1852 $message = $langs->transnoentitiesnoconv(
"Hello").
" ".$destinataire->firstname.
",\n";
1855 $message .= $langs->transnoentities(
"HolidaysValidatedBody",
dol_print_date($objecttmp->date_debut,
'day'),
dol_print_date($objecttmp->date_fin,
'day')).
"\n";
1857 $message .=
"- ".$langs->transnoentitiesnoconv(
"ValidatedBy").
" : ".
dolGetFirstLastname($expediteur->firstname, $expediteur->lastname).
"\n";
1859 $message .=
"- ".$langs->transnoentitiesnoconv(
"Link").
" : ".
$dolibarr_main_url_root.
"/holiday/card.php?id=".$objecttmp->id.
"\n\n";
1862 $trackid =
'leav'.$objecttmp->id;
1864 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
1865 $mail =
new CMailFile($subject, $emailTo, $emailFrom, $message, array(), array(), array(),
'',
'', 0, 0,
'',
'', $trackid);
1868 $result = $mail->sendfile();
1871 setEventMessages($mail->error, $mail->errors,
'warnings');
1877 $langs->load(
"errors");
1878 setEventMessages($langs->trans(
'ErrorNotApproverForHoliday', $objecttmp->ref),
null,
'errors');
1881 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1889 setEventMessages($langs->trans(
"RecordsApproved", $nbok),
null,
'mesgs');
1890 } elseif ($nbok == 1) {
1891 setEventMessages($langs->trans(
"RecordAproved"),
null,
'mesgs');
1899if (!$error && ($massaction ==
'increaseholiday' || ($action ==
'increaseholiday' && $confirm ==
'yes')) && $permissiontoapprove && is_array($toselect)) {
1900 '@phan-var-force Holiday $holiday';
1903 $objecttmp =
new $objectclass($db);
1908 if ($nbdaysholidays <= 0) {
1909 setEventMessages($langs->trans(
"WrongAmount"),
null,
'errors');
1914 foreach ($toselect as $toselectid) {
1915 $balancecpuser = $objecttmp->getCPforUser($toselectid, $typeholiday);
1916 if (!empty($balancecpuser)) {
1917 $newnbdaysholidays = $nbdaysholidays + $balancecpuser;
1919 $newnbdaysholidays = $nbdaysholidays;
1921 $result = $holiday->addLogCP($user->id, $toselectid, $langs->transnoentitiesnoconv(
'ManualUpdate'), $newnbdaysholidays, $typeholiday);
1923 setEventMessages($holiday->error, $holiday->errors,
'errors');
1928 $objecttmp->updateSoldeCP($toselectid, $newnbdaysholidays, $typeholiday);
1932 setEventMessages($langs->trans(
"ErrorUpdatingUsersCP"),
null,
'errors');
1941 setEventMessages($langs->trans(
"HolidayRecordsIncreased", $nbok),
null,
'mesgs');
1942 } elseif ($nbok == 1) {
1943 setEventMessages($langs->trans(
"HolidayRecordIncreased"),
null,
'mesgs');
1946 $toselect = array();
1953if (!$error && ($massaction ==
'clonetasks' || ($action ==
'clonetasks' && $confirm ==
'yes'))) {
1956 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
1958 $origin_task =
new Task($db);
1959 $clone_task =
new Task($db);
1960 $newproject =
new Project($db);
1964 $iscontactofnewproject = 0;
1965 if (empty($newproject->public)) {
1966 $tmps = $newproject->getProjectsAuthorizedForUser($user, 0, 1, 0,
'(fk_statut:=:1)');
1967 $tmparray = explode(
',', $tmps);
1968 if (in_array($newproject->id, $tmparray)) {
1969 $iscontactofnewproject = 1;
1974 $permisstiontoadd =
false;
1975 if ($user->hasRight(
'project',
'all',
'creer') || ($user->hasRight(
'project',
'creer') && ($newproject->public || $iscontactofnewproject))) {
1976 $permisstiontoadd =
true;
1979 if ($permisstiontoadd) {
1980 $taskidsmapping = array();
1981 $clonedtaskoldparent = array();
1986 $authorizedsourceprojects =
null;
1987 if (!$user->hasRight(
'projet',
'all',
'lire')) {
1988 $sourceprojectstatic =
new Project($db);
1989 $tmps = $sourceprojectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1990 $authorizedsourceprojects = explode(
',', $tmps);
1993 foreach (
GETPOST(
'selected') as $task) {
1994 if ($origin_task->fetch($task,
'', 0) <= 0) {
1999 if (is_array($authorizedsourceprojects) && !in_array($origin_task->fk_project, $authorizedsourceprojects)) {
2000 setEventMessages($langs->trans(
'NotEnoughPermissions'),
null,
'errors');
2008 require_once DOL_DOCUMENT_ROOT .
"/core/modules/project/task/" .
getDolGlobalString(
'PROJECT_TASK_ADDON') .
'.php';
2009 $modTask =
new $classnamemodtask();
2010 '@phan-var-force ModeleNumRefTask $modTask';
2012 $defaultref = $modTask->getNextValue(
null, $clone_task);
2016 $clone_task->fk_project =
GETPOSTINT(
'projectid');
2017 $clone_task->ref = $defaultref;
2018 $clone_task->label = $origin_task->label;
2019 $clone_task->description = $origin_task->description;
2020 $clone_task->planned_workload = $origin_task->planned_workload;
2021 $clone_task->fk_task_parent = $origin_task->fk_task_parent;
2022 $clone_task->date_c =
dol_now();
2023 $clone_task->date_start = $origin_task->date_start;
2024 $clone_task->date_end = $origin_task->date_end;
2025 $clone_task->progress = $origin_task->progress;
2028 $ret = $extrafields->setOptionalsFromPost(
null, $clone_task);
2030 $taskid = $clone_task->create($user);
2033 $result = $clone_task->add_contact(
GETPOSTINT(
"userid"),
'TASKEXECUTIVE',
'internal');
2034 $taskidsmapping[$task] = $taskid;
2035 $clonedtaskoldparent[$taskid] = $origin_task->fk_task_parent;
2038 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2039 $langs->load(
"projects");
2040 setEventMessages($langs->trans(
'NewTaskRefSuggested'),
null,
'warnings');
2041 $duplicate_code_error =
true;
2043 setEventMessages($clone_task->error, $clone_task->errors,
'errors');
2055 foreach ($clonedtaskoldparent as $newtaskid => $oldparentid) {
2056 if (empty($oldparentid)) {
2059 $newparentid = isset($taskidsmapping[$oldparentid]) ? $taskidsmapping[$oldparentid] : 0;
2060 $remaptask =
new Task($db);
2061 if ($remaptask->fetch($newtaskid) > 0 && $remaptask->fk_task_parent != $newparentid) {
2062 $remaptask->fk_task_parent = $newparentid;
2063 if ($remaptask->update($user) < 0) {
2064 setEventMessages($remaptask->error, $remaptask->errors,
'errors');
2072 setEventMessages($langs->trans(
'NumberOfTasksCloned', $num),
null,
'mesgs');
2073 header(
"Location: ".DOL_URL_ROOT.
'/projet/tasks.php?id='.
GETPOSTINT(
'projectid'));
2077 setEventMessages($langs->trans(
'NotEnoughPermissions'),
null,
'errors');
2081if (!$error && $action ==
'createcreditnote' && $permissiontoadd) {
2084 setEventMessages($langs->trans(
'CreditNoteNotCreatedStockCalculateOnBillEnabled'),
null,
'errors');
2085 header(
"Location: ".DOL_URL_ROOT.
'/compta/facture/list.php?mainmenu=compta&leftmenu=facture');
2089 $objecttmp =
new $objectclass($db);
2090 if ($objecttmp->element ==
'facture' || $objecttmp->element ==
'invoice') {
2095 $unique_arr = array_unique($toselect);
2096 foreach ($unique_arr as $toselectid) {
2097 $sourceinvoice = $toselectid;
2098 $result = $objecttmp->fetch($sourceinvoice);
2102 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
2103 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedSourceInvoiceNotFound', $sourceinvoice);
2108 $isSupportedType =
false;
2110 $isSupportedType =
true;
2113 $isSupportedType =
true;
2116 $isSupportedType =
true;
2119 if (!$isSupportedType) {
2128 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedInvoiceTypeNotSupported', $objecttmp->ref, $listtype[$objecttmp->type]);
2134 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedInvoiceNotValidated', $objecttmp->ref);
2139 $totalpaid = $objecttmp->getSommePaiement();
2140 $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
2141 $totaldeposits = $objecttmp->getSumDepositsUsed();
2142 if ($totalpaid > 0) {
2143 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedPaymentAlreadyDone', $objecttmp->ref);
2146 if ($totalcreditnotes > 0) {
2147 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedCreditNoteAlreadyUsed', $objecttmp->ref);
2150 if ($totaldeposits > 0) {
2151 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedDepositAlreadyUsed', $objecttmp->ref);
2159 $object->entity = $objecttmp->entity;
2160 $object->socid = $objecttmp->socid;
2161 $object->subtype = $objecttmp->subtype;
2165 $object->ref_client = $objecttmp->ref_client;
2166 $object->ref_customer = $objecttmp->ref_customer;
2167 $object->fk_project = $objecttmp->fk_project;
2168 $object->cond_reglement_id = 0;
2169 $object->fk_account = $objecttmp->fk_account;
2170 $object->fk_incoterms = $objecttmp->fk_incoterms;
2171 $object->location_incoterms = $objecttmp->location_incoterms;
2172 $object->multicurrency_code = $objecttmp->multicurrency_code;
2173 $object->multicurrency_tx = $objecttmp->multicurrency_tx;
2175 $object->fk_facture_source = $sourceinvoice;
2179 if ($objecttmp->isSituationInvoice()) {
2180 $object->situation_counter = $objecttmp->situation_counter;
2181 $object->situation_cycle_ref = $objecttmp->situation_cycle_ref;
2182 $objecttmp->fetchPreviousNextSituationInvoice();
2189 $TMsg[] = $langs->trans(
'CreditNoteNotCreated', $objecttmp->ref);
2193 $facture_source = $objecttmp;
2196 $object->copy_linked_contact($objecttmp,
'internal');
2197 $object->copy_linked_contact($objecttmp,
'external');
2200 if (!empty($facture_source->lines)) {
2201 $fk_parent_line = 0;
2203 foreach ($facture_source->lines as $line) {
2205 if (method_exists($line,
'fetch_optionals')) {
2207 $line->fetch_optionals();
2211 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
2212 $fk_parent_line = 0;
2215 if ($facture_source->isSituationInvoice()) {
2216 $source_fk_prev_id = $line->fk_prev_id;
2217 $line->fk_prev_id = $line->id;
2219 if (!empty($facture_source->tab_previous_situation_invoice)) {
2222 $tab_jumped_credit_notes = array();
2223 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
2224 $searchPreviousInvoice =
true;
2225 while ($searchPreviousInvoice) {
2226 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
2227 $searchPreviousInvoice =
false;
2231 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
2237 $maxPrevSituationPercent = 0;
2238 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2239 if ($prevLine->id == $source_fk_prev_id) {
2240 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2243 $line->total_ht -= $prevLine->total_ht;
2244 $line->total_tva -= $prevLine->total_tva;
2245 $line->total_ttc -= $prevLine->total_ttc;
2246 $line->total_localtax1 -= $prevLine->total_localtax1;
2247 $line->total_localtax2 -= $prevLine->total_localtax2;
2249 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
2250 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
2251 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
2252 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
2257 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
2262 $maxPrevSituationPercent = 0;
2263 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
2264 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
2265 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
2266 $maxPrevSituationPercent = $prevLine->situation_percent;
2268 $line->total_ht -= $prevLine->total_ht;
2269 $line->total_tva -= $prevLine->total_tva;
2270 $line->total_ttc -= $prevLine->total_ttc;
2271 $line->total_localtax1 -= $prevLine->total_localtax1;
2272 $line->total_localtax2 -= $prevLine->total_localtax2;
2274 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
2275 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
2276 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
2277 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
2283 $line->situation_percent += $maxPrevSituationPercent;
2289 $line->fk_facture =
$object->id;
2290 $line->fk_parent_line = $fk_parent_line;
2292 $line->subprice = -$line->subprice;
2294 $line->total_ht = -$line->total_ht;
2295 $line->total_tva = -$line->total_tva;
2296 $line->total_ttc = -$line->total_ttc;
2297 $line->total_localtax1 = -$line->total_localtax1;
2298 $line->total_localtax2 = -$line->total_localtax2;
2300 $line->multicurrency_subprice = -$line->multicurrency_subprice;
2301 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
2302 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
2303 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
2305 $line->context[
'createcreditnotefrominvoice'] = 1;
2306 $result = $line->insert(0, 1);
2311 if ($result > 0 && $line->product_type == 9) {
2312 $fk_parent_line = $result;
2320 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
2321 $facture_source->fetch(
$object->fk_facture_source);
2322 $facture_source->fetchObjectLinked();
2324 if (!empty($facture_source->linkedObjectsIds)) {
2325 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
2326 $object->add_object_linked($sourcetype, current($TIds));
2332 $result =
$object->validate($user);
2335 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnValidation', $objecttmp->ref);
2341 $outputlangs = $langs;
2344 $newlang =
GETPOST(
'lang_id',
'aZ09');
2347 $newlang =
$object->thirdparty->default_lang;
2349 if (!empty($newlang)) {
2351 $outputlangs->setDefaultLang($newlang);
2352 $outputlangs->load(
'products');
2358 $result =
$object->generateDocument($model, $outputlangs, (
int) $hidedetails, (
int) $hidedesc, (
int) $hideref);
2370 $result = $discountcheck->fetch(0,
$object->id);
2373 if (empty($discountcheck->id)) {
2378 $amount_ht = $amount_tva = $amount_ttc = array();
2379 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
2383 foreach (
$object->lines as $line) {
2384 if ($line->product_type < 9 && $line->total_ht != 0) {
2385 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
2387 if (!isset($amount_ht[$keyforvatrate])) {
2388 $amount_ht[$keyforvatrate] = 0;
2390 $amount_ht[$keyforvatrate] += $line->total_ht;
2391 if (!isset($amount_tva[$keyforvatrate])) {
2392 $amount_tva[$keyforvatrate] = 0;
2394 $amount_tva[$keyforvatrate] += $line->total_tva;
2395 if (!isset($amount_ttc[$keyforvatrate])) {
2396 $amount_ttc[$keyforvatrate] = 0;
2398 $amount_ttc[$keyforvatrate] += $line->total_ttc;
2399 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
2400 $multicurrency_amount_ht[$keyforvatrate] = 0;
2402 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
2403 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
2404 $multicurrency_amount_tva[$keyforvatrate] = 0;
2406 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
2407 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
2408 $multicurrency_amount_ttc[$keyforvatrate] = 0;
2410 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
2417 $discount->description =
'(CREDIT_NOTE)';
2418 $discount->fk_soc =
$object->socid;
2419 $discount->socid =
$object->socid;
2420 $discount->socid =
$object->socid;
2421 $discount->fk_facture_source =
$object->id;
2426 foreach ($amount_ht as $tva_tx => $xxx) {
2427 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
2428 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
2429 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
2430 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
2431 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
2432 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
2433 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
2434 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
2435 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
2436 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
2437 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
2438 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
2443 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
2444 $vat_src_code = $reg[1];
2445 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
2448 $discount->tva_tx = abs((
float) $tva_tx);
2449 $discount->vat_src_code = $vat_src_code;
2451 $id_discount = $discount->create($user);
2452 if ($id_discount < 0) {
2458 if (empty($error) && $id_discount > 0) {
2460 $result =
$object->setPaid($user);
2466 $discount->fetch($id_discount);
2467 $result = $discount->link_to_invoice(0,
$object->fk_facture_source);
2469 setEventMessages($discount->error, $discount->errors,
'errors');
2470 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnDiscountLink', $objecttmp->ref);
2476 $objecttmp->fetch($objecttmp->id);
2477 if ($objecttmp->getRemainToPay(0) == 0) {
2478 $result = $objecttmp->setPaid($user);
2480 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
2481 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnSetPaidSourceInvoice', $objecttmp->ref);
2486 $outputlangs = $langs;
2489 $newlang =
GETPOST(
'lang_id',
'aZ09');
2492 $objecttmp->fetch_thirdparty();
2493 $newlang = $objecttmp->thirdparty->default_lang;
2495 if (!empty($newlang)) {
2497 $outputlangs->setDefaultLang($newlang);
2499 $ret = $objecttmp->fetch($objecttmp->id);
2501 $result = $objecttmp->generateDocument($objecttmp->model_pdf, $outputlangs, (
int) $hidedetails, (
int) $hidedesc, (
int) $hideref);
2503 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
2509 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnSourceInvoiceNotFullyPaidAfterDiscount', $objecttmp->ref);
2515 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnSetPaid', $objecttmp->ref);
2520 setEventMessages($discount->error, $discount->errors,
'errors');
2521 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnDiscount', $objecttmp->ref);
2526 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedAlreadyConverted', $objecttmp->ref);
2534 $TMsg[] = $langs->trans(
'CreditNoteCreated',
$object->ref, $objecttmp->ref);
2539 foreach ($TMsg as $msg) {
2540 setEventMessages($msg,
null,
'warnings');
2545 setEventMessages($langs->trans(
'CreditNotesCreated', $nbok),
null,
'mesgs');
2548 $toselect = array();
2549 header(
"Location: ".DOL_URL_ROOT.
'/compta/facture/list.php?mainmenu=compta&leftmenu=facture');
2552 setEventMessages($langs->trans(
'ThisMassActionIsOnlyForInvoices'),
null,
'errors');
2553 header(
"Location: ".DOL_URL_ROOT.
'/compta/facture/list.php?mainmenu=compta&leftmenu=facture');
2558if (empty($toselect)) {
2561$parameters[
'toselect'] = &$toselect;
2562$parameters[
'uploaddir'] = $uploaddir;
2563$parameters[
'massaction'] = $massaction;
2564$parameters[
'diroutputmassaction'] = isset($diroutputmassaction) ? $diroutputmassaction :
null;
2567$reshook = $hookmanager->executeHooks(
'doMassActions', $parameters,
$object, $action);
2569 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
global $dolibarr_main_url_root
Class to manage members of a foundation.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,...
Class to manage categories.
Class to manage customers orders.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
Class for ConferenceOrBoothAttendee.
Class to manage absolute discounts.
Class to manage invoices.
const TYPE_REPLACEMENT
Replacement invoice.
const STATUS_DRAFT
Draft status.
const TYPE_STANDARD
Standard invoice.
const TYPE_SITUATION
Situation invoice.
const TYPE_PROFORMA
Proforma invoice (should not be used.
const TYPE_DEPOSIT
Deposit invoice.
const TYPE_CREDIT_NOTE
Credit note invoice.
const STATUS_VALIDATED
Validated status.
const STATUS_DRAFT
Draft status.
const STATUS_REFUSED
Refused.
const STATUS_CANCELED
Canceled.
const STATUS_APPROVED
Approved.
Class to manage projects.
const STATUS_DRAFT
Draft status.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage translations.
Class to manage Dolibarr users.
num_open_day($timestampStart, $timestampEnd, $inhour=0, $lastday=0, $halfday=0, $countryCodeOrId='', $user_id=0)
Function to return number of working days (and text of units) between two dates (working days)
dol_most_recent_file($dir, $regexfilter='', $excludefilter=array('(\.meta|_preview.*\.png) $', '^\.'), $nohook=0, $mode=0, $limit=0)
Return file(s) into a directory (by default most recent)
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
dol_is_file($pathoffile)
Return if path is a file.
dol_dir_list($utf8_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_now($mode='gmt')
Return date for now.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dol_string_nospecial($str, $newstr='_', $badcharstoreplace='', $badcharstoremove='', $keepspaces=0)
Clean a string from all punctuation characters to use it as a ref or login.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
dolChmod($filepath, $newmask='')
Change mod of a file.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTFLOAT($paramname, $rounding='', $option=2)
Return the value of a $_GET or $_POST supervariable, converted into float.
dolGetFirstLastname($firstname, $lastname, $nameorder=-1)
Return firstname and lastname in correct order.
dol_concatdesc($text1, $text2, $forxml=false, $invert=false)
Concat 2 descriptions with a new line between them (second operand after first one with appropriate n...
complete_substitutions_array(&$substitutionarray, $outputlangs, $object=null, $parameters=null, $callfunc="completesubstitutionarray")
Complete the $substitutionarray with more entries coming from external module that had set the "subst...
make_substitutions($text, $substitutionarray, $outputlangs=null, $converttextinhtmlifnecessary=0)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dol_clone($srcobject, $native=2)
Create a clone of instance of object (new instance with same value for each properties) With native =...
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false, $decorate=0)
Output date in a string format according to outputlangs (or langs if not defined).
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
pdf_getFormat($outputlangs=null, $mode='setup')
Return array with format properties of default PDF format.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
pdf_getInstance($format='', $metric='mm', $pagetype='P')
Return a PDF instance object.
getObjectIdsRefusedToUser(User $user, $object, array $ids)
Return, among a list of ids of objects of the same type, the ids of the objects the user is not allow...
dol_hash($chain, $type='0', $nosalt=0, $mode=0)
Returns a hash (non reversible encryption) of a string.