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');
145if (!$error && $massaction && !in_array($massaction, array(
'increaseholiday',
'ventil',
'set_default_account')) && !empty($toselect) && is_array($toselect)) {
146 $objecttmpforaccesscheck =
new $objectclass($db);
148 if (!empty($refusedids)) {
149 $langs->load(
"errors");
150 setEventMessages($langs->trans(
"NotEnoughPermissions"),
null,
'errors');
155if (!$error && $massaction ==
'confirm_presend' && !
GETPOST(
'sendmail')) {
156 $massaction =
'presend';
159if (!$error && $massaction ==
'confirm_presend') {
163 $langs->load(
"mails");
164 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
165 include_once DOL_DOCUMENT_ROOT.
'/core/lib/signature.lib.php';
167 $listofobjectid = array();
168 $listofobjectthirdparties = array();
169 $listofobjectcontacts = array();
170 $listofobjectref = array();
171 $contactidtosend = array();
172 $attachedfilesThirdpartyObj = array();
173 $oneemailperrecipient = (
GETPOSTINT(
'oneemailperrecipient') ? 1 : 0);
177 $objecttmp =
new $objectclass($db);
180 $thirdparty =
new Societe($db);
181 if ($objecttmp->element ==
'expensereport') {
182 $thirdparty =
new User($db);
183 } elseif ($objecttmp->element ==
'contact') {
184 $thirdparty =
new Contact($db);
185 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
187 } elseif ($objecttmp->element ==
'holiday') {
188 $thirdparty =
new User($db);
189 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
193 foreach ($toselect as $toselectid) {
194 $objecttmp =
new $objectclass($db);
195 '@phan-var-force CommonObject $objecttmp';
197 $result = $objecttmp->fetch($toselectid);
199 $listofobjectid[$toselectid] = $toselectid;
203 $tmpobjectid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
204 if ($objecttmp->element ==
'societe') {
205 '@phan-var-force Societe $objecttmp';
207 $tmpobjectid = $objecttmp->id;
208 } elseif ($objecttmp->element ==
'contact') {
209 '@phan-var-force Contact $objecttmp';
211 $tmpobjectid = $objecttmp->id;
212 } elseif ($objecttmp->element ==
'expensereport') {
213 '@phan-var-force ExpenseReport $objecttmp';
215 $tmpobjectid = $objecttmp->fk_user_author;
216 } elseif ($objecttmp->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
217 '@phan-var-force Partnership $objecttmp';
219 $tmpobjectid = $objecttmp->fk_member;
220 } elseif ($objecttmp->element ==
'holiday') {
221 '@phan-var-force Holiday $objecttmp';
223 $tmpobjectid = $objecttmp->fk_user;
224 } elseif ($objecttmp->element ==
'conferenceorboothattendee') {
225 '@phan-var-force ConferenceOrBoothAttendee $objecttmp';
227 $tmpobjectid = $objecttmp->id;
229 if (empty($tmpobjectid)) {
233 if ($objectclass ==
'Facture') {
234 '@phan-var-force Facture $objecttmp';
236 $tmparraycontact = array();
237 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'BILLING');
238 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
239 foreach ($tmparraycontact as $data_email) {
240 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
243 } elseif ($objectclass ==
'CommandeFournisseur') {
244 '@phan-var-force CommandeFournisseur $objecttmp';
246 $tmparraycontact = array();
247 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'CUSTOMER');
248 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
249 foreach ($tmparraycontact as $data_email) {
250 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
255 $listofobjectthirdparties[$tmpobjectid] = $tmpobjectid;
256 $listofobjectref[$tmpobjectid][$toselectid] = $objecttmp;
262 if (
GETPOST(
'fromtype',
'alpha') ===
'user' && empty($user->email)) {
264 setEventMessages($langs->trans(
"NoSenderEmailDefined"),
null,
'warnings');
265 $massaction =
'presend';
268 $receiver =
GETPOST(
'receiver',
'alphawithlgt');
269 if (!is_array($receiver)) {
270 if (empty($receiver) || $receiver ==
'-1') {
273 $receiver = array($receiver);
276 if (!trim(
GETPOST(
'sendto',
'alphawithlgt')) && count($receiver) == 0 && count($listofobjectthirdparties) == 1) {
278 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailRecipient")),
null,
'warnings');
279 $massaction =
'presend';
282 if (!
GETPOST(
'subject',
'restricthtml')) {
284 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTopic")),
null,
'warnings');
285 $massaction =
'presend';
290 foreach ($listofobjectthirdparties as $thirdpartyid) {
291 $result = $thirdparty->fetch($thirdpartyid);
293 dol_print_error($db);
304 if (trim(
GETPOST(
'sendto',
'alphawithlgt'))) {
306 $tmparray[] = trim(
GETPOST(
'sendto',
'alphawithlgt'));
308 if (count($receiver) > 0 && is_object($thirdparty)) {
309 foreach ($receiver as $key => $val) {
311 if ($val ==
'thirdparty') {
312 $tmparray[] =
dol_string_nospecial((
string) $thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
313 } elseif ($val && method_exists($thirdparty,
'contact_get_property')) {
314 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
319 $sendto = implode(
',', $tmparray);
322 $receivercc =
GETPOST(
'receivercc',
'alphawithlgt');
323 if (!is_array($receivercc)) {
324 if ($receivercc ==
'-1') {
325 $receivercc = array();
327 $receivercc = array($receivercc);
331 if (trim(
GETPOST(
'sendtocc',
'alphawithlgt'))) {
332 $tmparray[] = trim(
GETPOST(
'sendtocc',
'alphawithlgt'));
334 if (count($receivercc) > 0) {
335 foreach ($receivercc as $key => $val) {
337 if ($val ==
'thirdparty') {
338 $tmparray[] =
dol_string_nospecial((
string) $thirdparty->name,
' ', array(
",")).
' <'.$thirdparty->email.
'>';
340 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
345 $sendtocc = implode(
',', $tmparray);
348 $listofqualifiedobj = array();
349 $listofqualifiedref = array();
350 $thirdpartywithoutemail = array();
352 foreach ($listofobjectref[$thirdpartyid] as $objectid => $objectobj) {
359 $langs->load(
"errors");
361 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyProposalNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
365 $langs->load(
"errors");
367 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyOrderNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
371 $langs->load(
"errors");
373 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyInvoiceValidatedCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
378 if (empty($sendto)) {
379 if ($objectobj->element ==
'societe') {
380 $sendto = $objectobj->email;
381 } elseif ($objectobj->element ==
'expensereport') {
382 $fuser =
new User($db);
383 $fuser->fetch($objectobj->fk_user_author);
384 $sendto = $fuser->email;
385 } elseif ($objectobj->element ==
'contact') {
387 $fcontact->fetch($objectobj->id);
388 $sendto = $fcontact->email;
389 } elseif ($objectobj->element ==
'partnership' &&
getDolGlobalString(
'PARTNERSHIP_IS_MANAGED_FOR') ==
'member') {
391 $fadherent->fetch($objectobj->fk_member);
392 $sendto = $fadherent->email;
393 } elseif ($objectobj->element ==
'holiday') {
394 $fuser =
new User($db);
395 $fuser->fetch($objectobj->fk_user);
396 $sendto = $fuser->email;
397 } elseif ($objectobj->element ==
'facture' && !empty($listofobjectcontacts[$objectid])) {
398 $emails_to_sends = array();
399 $objectobj->fetch_thirdparty();
400 $contactidtosend = array();
401 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
402 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
403 if (!in_array($contactemailid, $contactidtosend)) {
404 $contactidtosend[] = $contactemailid;
407 if (count($emails_to_sends) > 0) {
408 $sendto = implode(
',', $emails_to_sends);
410 } elseif ($objectobj->element ==
'order_supplier' && !empty($listofobjectcontacts[$objectid])) {
411 $emails_to_sends = array();
412 $objectobj->fetch_thirdparty();
413 $contactidtosend = array();
414 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
415 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
416 if (!in_array($contactemailid, $contactidtosend)) {
417 $contactidtosend[] = $contactemailid;
420 if (count($emails_to_sends) > 0) {
421 $sendto = implode(
',', $emails_to_sends);
423 } elseif ($objectobj->element ==
'conferenceorboothattendee') {
424 $sendto = $objectobj->email;
426 $objectobj->fetch_thirdparty();
427 $sendto = $objectobj->thirdparty->email;
431 if (empty($sendto)) {
432 if ($objectobj->element ==
'societe') {
434 $objectobj->thirdparty = $objectobj;
439 if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id])) {
440 $resaction .=
'<div class="error">'.$langs->trans(
'NoRecipientEmail', $objectobj->thirdparty->name).
'</div><br>';
442 dol_syslog(
'No recipient for thirdparty: '.$objectobj->thirdparty->name, LOG_WARNING);
443 $thirdpartywithoutemail[$objectobj->thirdparty->id] = 1;
447 if (
GETPOST(
'addmaindocfile')) {
454 $filedir = $uploaddir.
'/'.$subdir.dol_sanitizeFileName($objectobj->ref);
455 $filepath = $filedir.
'/'.$filename;
458 if ($objectobj->element ==
'invoice_supplier') {
459 $fileparams =
dol_most_recent_file($uploaddir.
'/'.
get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element).$objectobj->ref, preg_quote($objectobj->ref,
'/').
'([^\-])+');
460 $filepath = $fileparams[
'fullname'];
463 if (
getDolGlobalInt(
'MAIL_MASS_ACTION_SEARCH_MOST_RECENT_FILE_IF_NOT_FOUND') && isset($filepath) && !
dol_is_file($filepath)) {
465 if (isset($fileparams)) {
466 $filepath = $fileparams[
'fullname'];
467 $filename = $fileparams[
'name'];
472 $filename_found =
'';
473 $filepath_found =
'';
474 $file_check_list = array();
475 $file_check_list[] = array(
479 if (
getDolGlobalString(
'MAIL_MASS_ACTION_ADD_LAST_IF_MAIN_DOC_NOT_FOUND') && !empty($objectobj->last_main_doc)) {
480 $file_check_list[] = array(
481 'name' => basename($objectobj->last_main_doc),
482 'path' => DOL_DATA_ROOT .
'/' . $objectobj->last_main_doc,
485 foreach ($file_check_list as $file_check_arr) {
487 $filename_found = $file_check_arr[
'name'];
488 $filepath_found = $file_check_arr[
'path'];
493 if ($filepath_found) {
495 $attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array(
496 'paths' => array($filepath_found),
497 'names' => array($filename_found),
502 $langs->load(
"errors");
503 foreach ($file_check_list as $file_check_arr) {
504 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorCantReadFile', $file_check_arr[
'path']).
'</div><br>';
505 dol_syslog(
'Failed to read file: '.$file_check_arr[
'path'], LOG_WARNING);
512 $listofqualifiedobj[$objectid] = $objectobj;
513 $listofqualifiedref[$objectid] = $objectobj->ref;
520 if (count($listofqualifiedobj) > 0) {
521 $langs->load(
"commercial");
525 $fromtype =
GETPOST(
'fromtype');
526 if ($fromtype ===
'user') {
527 $email_from =
dol_string_nospecial($user->getFullName($langs),
' ', array(
",")).
' <'.$user->email.
'>';
528 } elseif ($fromtype ===
'company') {
530 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
532 $email_from = trim($tmp[((
int) $reg[1] - 1)]);
533 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
534 $sql =
"SELECT rowid, label, email FROM ".MAIN_DB_PREFIX.
"c_email_senderprofile WHERE rowid = ".(int) $reg[1];
535 $resql = $db->query($sql);
536 $obj = $db->fetch_object($resql);
540 } elseif (preg_match(
'/from_template_(\d+)/', $fromtype, $reg)) {
541 $sql =
"SELECT rowid, email_from FROM ".MAIN_DB_PREFIX.
"c_email_templates WHERE rowid = ".(int) $reg[1];
542 $resql = $db->query($sql);
543 $obj = $db->fetch_object($resql);
545 $email_from = $obj->email_from;
548 $email_from =
GETPOST(
'fromname').
' <'.
GETPOST(
'frommail',
'email').
'>';
551 $replyto = $email_from;
552 $subject =
GETPOST(
'subject',
'restricthtml');
553 $message =
GETPOST(
'message',
'restricthtml');
555 $sendtobcc =
GETPOST(
'sendtoccc');
556 if ($objectclass ==
'Propal') {
559 if ($objectclass ==
'Commande') {
562 if ($objectclass ==
'Facture') {
565 if ($objectclass ==
'SupplierProposal') {
566 $sendtobcc .= (!
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO') ?
'' : (($sendtobcc ?
", " :
"") .
getDolGlobalString(
'MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO')));
568 if ($objectclass ==
'CommandeFournisseur') {
571 if ($objectclass ==
'FactureFournisseur') {
574 if ($objectclass ==
'Project') {
580 $looparray = array();
581 if (!$oneemailperrecipient) {
582 $looparray = $listofqualifiedobj;
583 foreach ($looparray as $key => $objecttmp) {
584 $looparray[$key]->thirdparty = $thirdparty;
587 $objectforloop =
new $objectclass($db);
588 $objectforloop->thirdparty = $thirdparty;
589 $looparray[0] = $objectforloop;
592 dol_syslog(
"We have set an array of ".count($looparray).
" emails to send. oneemailperrecipient=".$oneemailperrecipient);
594 foreach ($looparray as $objectid => $objecttmp) {
596 if (
isModEnabled(
'project') && method_exists($objecttmp,
'fetchProject') && is_null($objecttmp->project)) {
597 $objecttmp->fetchProject();
599 $substitutionarray = getCommonSubstitutionArray($langs, 0,
null, $objecttmp);
600 $substitutionarray[
'__ID__'] = ($oneemailperrecipient ? implode(
', ', array_keys($listofqualifiedobj)) : $objecttmp->id);
601 $substitutionarray[
'__REF__'] = ($oneemailperrecipient ? implode(
', ', $listofqualifiedref) : $objecttmp->
ref);
602 $substitutionarray[
'__EMAIL__'] = $thirdparty->email;
603 $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"/>';
605 if ($oneemailperrecipient) {
606 $substitutionarray[
'__ONLINE_PAYMENT_URL__'] =
'';
607 $substitutionarray[
'__ONLINE_PAYMENT_TEXT_AND_URL__'] =
'';
610 $parameters = array(
'mode' =>
'formemail');
612 if (!empty($listofobjectthirdparties)) {
613 $parameters[
'listofobjectthirdparties'] = $listofobjectthirdparties;
615 if (!empty($listofobjectref)) {
616 $parameters[
'listofobjectref'] = $listofobjectref;
624 $attachedfiles = array(
'paths' => array(),
'names' => array(),
'mimes' => array());
625 if ($oneemailperrecipient) {
627 if (is_array($attachedfilesThirdpartyObj[$thirdparty->id]) && count($attachedfilesThirdpartyObj[$thirdparty->id])) {
628 foreach ($attachedfilesThirdpartyObj[$thirdparty->id] as $keyObjId => $objAttachedFiles) {
630 $attachedfiles = array(
631 'paths' => array_merge($attachedfiles[
'paths'], $objAttachedFiles[
'paths']),
632 'names' => array_merge($attachedfiles[
'names'], $objAttachedFiles[
'names']),
633 'mimes' => array_merge($attachedfiles[
'mimes'], $objAttachedFiles[
'mimes'])
637 } elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) {
640 $attachedfiles = $attachedfilesThirdpartyObj[$thirdparty->id][$objectid];
643 $filepath = $attachedfiles[
'paths'];
644 $filename = $attachedfiles[
'names'];
645 $mimetype = $attachedfiles[
'mimes'];
648 if ($oneemailperrecipient) {
649 $trackid =
'thi'.$thirdparty->id;
650 if ($objecttmp->element ==
'expensereport') {
651 $trackid =
'use'.$thirdparty->id;
652 } elseif ($objecttmp->element ==
'contact') {
653 $trackid =
'ctc'.$thirdparty->id;
654 } elseif ($objecttmp->element ==
'holiday') {
655 $trackid =
'use'.$thirdparty->id;
658 $trackid = strtolower(get_class($objecttmp));
659 if (get_class($objecttmp) ==
'Contact') {
661 } elseif (get_class($objecttmp) ==
'Contrat') {
663 } elseif (get_class($objecttmp) ==
'Propal') {
665 } elseif (get_class($objecttmp) ==
'Commande') {
667 } elseif (get_class($objecttmp) ==
'Facture') {
669 } elseif (get_class($objecttmp) ==
'SupplierProposal') {
671 } elseif (get_class($objecttmp) ==
'CommandeFournisseur') {
673 } elseif (get_class($objecttmp) ==
'FactureFournisseur') {
677 $trackid .= $objecttmp->id;
683 if (empty($sendcontext)) {
684 $sendcontext =
'standard';
688 $vardir =
$conf->user->dir_output.
"/".$user->id;
689 $upload_dir_tmp = $vardir.
'/temp';
692 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
693 $mailfile =
new CMailFile($subjectreplaced, (
string) $sendto, $email_from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, (
int) $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext,
'', $upload_dir_tmp);
694 if ($mailfile->error) {
695 $resaction .=
'<div class="error">'.$mailfile->error.
'</div>';
697 $result = $mailfile->sendfile();
699 $resaction .= $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($mailfile->addr_from, 2), $mailfile->getValidAddress($mailfile->addr_to, 2)).
'<br>';
704 foreach ($listofqualifiedobj as $objid2 => $objectobj2) {
705 if ((!$oneemailperrecipient) && $objid2 != $objectid) {
709 dol_syslog(
"Try to insert email event into agenda for objid=".$objid2.
" => objectobj=".get_class($objectobj2));
718 $actionmsg = $langs->transnoentities(
'MailSentByTo', $email_from, (
string) $sendto);
721 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'Bcc').
": ".$sendtocc);
723 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'MailTopic').
": ".$subjectreplaced);
724 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'TextUsedInTheMessageBody').
":");
730 $objectobj2->sendtoid = (empty($contactidtosend) ? 0 : $contactidtosend);
731 $objectobj2->actionmsg = $actionmsg;
732 $objectobj2->actionmsg2 = $actionmsg2;
733 $objectobj2->fk_element = $objid2;
734 $objectobj2->elementtype = $objectobj2->element;
736 $objectobj2->actionmsg2 = $subjectreplaced;
739 $triggername = strtoupper(get_class($objectobj2)).
'_SENTBYMAIL';
740 if ($triggername ==
'SOCIETE_SENTBYMAIL') {
741 $triggername =
'COMPANY_SENTBYMAIL';
743 if ($triggername ==
'CONTRAT_SENTBYMAIL') {
744 $triggername =
'CONTRACT_SENTBYMAIL';
746 if ($triggername ==
'COMMANDE_SENTBYMAIL') {
747 $triggername =
'ORDER_SENTBYMAIL';
749 if ($triggername ==
'FACTURE_SENTBYMAIL') {
750 $triggername =
'BILL_SENTBYMAIL';
752 if ($triggername ==
'EXPEDITION_SENTBYMAIL') {
753 $triggername =
'SHIPPING_SENTBYMAIL';
755 if ($triggername ==
'COMMANDEFOURNISSEUR_SENTBYMAIL') {
756 $triggername =
'ORDER_SUPPLIER_SENTBYMAIL';
758 if ($triggername ==
'FACTUREFOURNISSEUR_SENTBYMAIL') {
759 $triggername =
'BILL_SUPPLIER_SENTBYMAIL';
761 if ($triggername ==
'SUPPLIERPROPOSAL_SENTBYMAIL') {
762 $triggername =
'PROPOSAL_SUPPLIER_SENTBYMAIL';
764 if ($triggername ==
'PROJET_SENTBYMAIL') {
765 $triggername =
'PROJECT_SENTBYMAIL';
768 if (!empty($triggername)) {
770 $result = $objectobj2->call_trigger($triggername, $user);
777 setEventMessages($db->lasterror(),
null,
'errors');
778 dol_syslog(
"Error in trigger ".$triggername.
' '.$db->lasterror(), LOG_ERR);
785 $langs->load(
"other");
786 if ($mailfile->error) {
787 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $email_from, (
string) $sendto);
788 $resaction .=
'<br><div class="error">'.$mailfile->error.
'</div>';
790 $resaction .=
'<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
792 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $email_from, (
string) $sendto) .
'<br><div class="error">(unhandled error)</div>';
800 $resaction .= ($resaction ?
'<br>' : $resaction);
801 $resaction .=
'<strong>'.$langs->trans(
"ResultOfMailSending").
':</strong><br>'.
"\n";
802 $resaction .= $langs->trans(
"NbSelected").
': '.count($toselect).
"\n<br>";
803 $resaction .= $langs->trans(
"NbIgnored").
': '.($nbignored ? $nbignored : 0).
"\n<br>";
804 $resaction .= $langs->trans(
"NbSent").
': '.($nbsent ? $nbsent : 0).
"\n<br>";
809 setEventMessages($langs->trans(
"EMailSentForNElements", $nbsent.
'/'.count($toselect)),
null,
'mesgs');
810 setEventMessages($resaction,
null,
'mesgs');
813 setEventMessages($resaction,
null,
'warnings');
822if (!$error && $massaction ==
'cancelorders') {
827 $orders =
GETPOST(
'toselect',
'array:int');
828 foreach ($orders as $id_order) {
830 if ($cmd->fetch($id_order) <= 0) {
835 $langs->load(
'errors');
836 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref),
null,
'errors');
841 $result = $cmd->cancel($user);
845 setEventMessages($cmd->error, $cmd->errors,
'errors');
853 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null,
'mesgs');
861if (!$error && $massaction ==
"builddoc" && $permissiontoread && !
GETPOST(
'button_search')) {
862 if (empty($diroutputmassaction)) {
863 dol_print_error(
null,
'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
867 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
868 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
869 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
871 $objecttmp =
new $objectclass($db);
872 $listofobjectid = array();
873 $listofobjectthirdparties = array();
874 $listofobjectref = array();
875 foreach ($toselect as $toselectid) {
876 $objecttmp =
new $objectclass($db);
877 $result = $objecttmp->fetch($toselectid);
879 $listofobjectid[$toselectid] = $toselectid;
880 $thirdpartyid = !empty($objecttmp->fk_soc) ? $objecttmp->fk_soc : $objecttmp->socid;
881 $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid;
882 $listofobjectref[$toselectid] = $objecttmp->ref;
886 $arrayofinclusion = array();
888 'listofobjectref' => $listofobjectref,
889 'arrayofinclusion' => &$arrayofinclusion,
891 $reshook = $hookmanager->executeHooks(
'updateSearchRegexToMergeDoc', $parameters,
$object, $action);
893 if (empty($reshook)) {
894 foreach ($listofobjectref as $tmppdf) {
897 foreach ($listofobjectref as $tmppdf) {
898 $arrayofinclusion[] =
'^'.preg_quote(
dol_sanitizeFileName($tmppdf),
'/').
'_[\w\-\'\&\.]+\.pdf$';
902 $listoffiles =
dol_dir_list($uploaddir,
'all', 1, $arrayofinclusion,
'\.meta$|\.png$',
'date', SORT_DESC, 0, 1);
904 dol_syslog(
"Found ".count($listoffiles).
" files");
909 foreach ($listofobjectref as $basename) {
911 foreach ($listoffiles as $filefound) {
912 if (strstr($filefound[
"name"], $basename)) {
913 $files[] = $filefound[
'fullname'];
920 $outputlangs = $langs;
923 $newlang =
GETPOST(
'lang_id',
'aZ09');
928 if (!empty($newlang)) {
930 $outputlangs->setDefaultLang($newlang);
939 $filename = preg_replace(
'/\s/',
'_', $filename);
942 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status == $objecttmp::STATUS_VALIDATED) {
943 if ($option ==
'late') {
950 $filename .=
'_'.$year;
953 $filename .=
'_'.$month;
956 if (count($files) > 0) {
958 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
961 foreach ($files as $f) {
962 $input_files .=
' '.escapeshellarg($f);
965 $cmd =
'pdftk '.$input_files.
' cat output '.escapeshellarg($file);
969 if (file_exists($file)) {
972 $langs->load(
"exports");
973 setEventMessages($langs->trans(
'FileSuccessfullyBuilt', $filename.
'_'.
dol_print_date($now,
'dayhourlog')),
null,
'mesgs');
975 setEventMessages($langs->trans(
'ErrorPDFTkOutputFileNotFound'),
null,
'errors');
978 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
983 $page_largeur = $formatarray[
'width'];
984 $page_hauteur = $formatarray[
'height'];
985 $format = array($page_largeur, $page_hauteur);
989 if (class_exists(
'TCPDF')) {
990 $pdf->setPrintHeader(
false);
991 $pdf->setPrintFooter(
false);
996 $pdf->SetCompression(
false);
1001 foreach ($files as $file) {
1003 $pagecount = $pdf->setSourceFile($file);
1004 for ($i = 1; $i <= $pagecount; $i++) {
1005 $tplidx = $pdf->importPage($i);
1006 $s = $pdf->getTemplatesize($tplidx);
1007 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1008 $pdf->useTemplate($tplidx);
1017 $filename = preg_replace(
'/\s/',
'_', $filename);
1021 if (in_array($objecttmp->element, array(
'facture',
'invoice_supplier')) && $search_status == $objecttmp::STATUS_VALIDATED) {
1022 if ($option ==
'late') {
1028 if (!empty($year)) {
1029 $filename .=
'_'.$year;
1031 if (!empty($month)) {
1032 $filename .=
'_'.$month;
1036 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
1037 $pdf->Output($file,
'F');
1040 $langs->load(
"exports");
1041 setEventMessages($langs->trans(
'FileSuccessfullyBuilt', $filename.
'_'.
dol_print_date($now,
'dayhourlog')),
null,
'mesgs');
1043 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'),
null,
'errors');
1049if ($action ==
'remove_file') {
1050 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1052 $langs->load(
"other");
1053 $upload_dir = $diroutputmassaction;
1054 $file = $upload_dir.
'/'.
GETPOST(
'file');
1057 setEventMessages($langs->trans(
"FileWasRemoved",
GETPOST(
'file')),
null,
'mesgs');
1059 setEventMessages($langs->trans(
"ErrorFailToDeleteFile",
GETPOST(
'file')),
null,
'errors');
1066if (!$error && $massaction ==
'validate' && $permissiontoadd) {
1067 $objecttmp =
new $objectclass($db);
1069 if (($objecttmp->element ==
'facture' || $objecttmp->element ==
'invoice') &&
isModEnabled(
'stock') &&
getDolGlobalString(
'STOCK_CALCULATE_ON_BILL')) {
1070 $langs->load(
"errors");
1071 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
1075 $langs->load(
"errors");
1076 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'),
null,
'errors');
1079 if ($objecttmp->element ==
'facture') {
1082 $sql =
"SELECT rowid FROM ".MAIN_DB_PREFIX.
"facture";
1083 $sql .=
" WHERE rowid IN (".$db->sanitize(implode(
",", $toselect)).
")";
1084 $sql .=
" ORDER BY datef";
1086 $resql = $db->query($sql);
1089 while (!empty($arr = $db->fetch_row($resql))) {
1090 $toselectnew[] = $arr[0];
1092 $toselect = (empty($toselectnew)) ? $toselect : $toselectnew;
1094 dol_print_error($db);
1106 $perrecordtransaction = (int)
getDolGlobalInt(
'MAIN_MASSVALIDATE_'.strtoupper($objectclass).
'_NO_GLOBAL_TRANSACTION');
1107 if (!$perrecordtransaction) {
1112 foreach ($toselect as $toselectid) {
1113 if ($perrecordtransaction) {
1116 $result = $objecttmp->fetch($toselectid);
1118 if (method_exists($objecttmp,
'validate')) {
1119 $result = $objecttmp->validate($user);
1120 } elseif (method_exists($objecttmp,
'setValid')) {
1121 $result = $objecttmp->setValid($user);
1123 $objecttmp->error =
'No method validate or setValid on this object';
1127 $langs->load(
"errors");
1128 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref),
null,
'errors');
1130 if ($perrecordtransaction) {
1134 } elseif ($result < 0) {
1135 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1137 if ($perrecordtransaction) {
1145 $outputlangs = $langs;
1148 $newlang =
GETPOST(
'lang_id',
'aZ09');
1150 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && property_exists($objecttmp,
'thirdparty')) {
1151 if ((property_exists($objecttmp,
'socid') || property_exists($objecttmp,
'fk_soc')) && empty($objecttmp->thirdparty)) {
1152 $objecttmp->fetch_thirdparty();
1154 if (!empty($objecttmp->thirdparty)) {
1155 $newlang = $objecttmp->thirdparty->default_lang;
1158 if (!empty($newlang)) {
1160 $outputlangs->setDefaultLang($newlang);
1161 $outputlangs->load(
'products');
1163 $model = $objecttmp->model_pdf;
1164 $ret = $objecttmp->fetch($objecttmp->id);
1167 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
1168 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
1169 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
1170 $moreparams = isset($moreparams) ? $moreparams :
null;
1172 $result = $objecttmp->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1174 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1178 if ($perrecordtransaction) {
1183 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1185 if ($perrecordtransaction) {
1194 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null,
'mesgs');
1196 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
1198 if (!$perrecordtransaction) {
1201 } elseif (!$perrecordtransaction) {
1208if (!$error && ($massaction ==
'delete' || ($action ==
'delete' && $confirm ==
'yes')) && $permissiontodelete) {
1211 $objecttmp =
new $objectclass($db);
1212 '@phan-var-force CommonObject $objecttmp';
1220 $unique_arr = array_unique($toselect);
1221 foreach ($unique_arr as $toselectid) {
1222 $result = $objecttmp->fetch($toselectid);
1226 $langs->load(
"errors");
1228 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).
'</div><br>';
1232 if (method_exists($objecttmp,
'is_erasable') && $objecttmp->is_erasable() <= 0) {
1233 $langs->load(
"errors");
1235 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorRecordHasChildren').
' '.$objecttmp->ref.
'</div><br>';
1240 $langs->load(
"errors");
1242 $TMsg[] =
'<div class="error">'.$langs->trans(
'ErrorLeaveRequestMustBeDraftCanceledOrRefusedToBeDeleted', $objecttmp->ref).
'</div><br>';
1246 if ($objectclass ==
"Task" && $objecttmp->hasChildren() > 0) {
1247 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".((int) $objecttmp->id);
1248 $res = $db->query($sql);
1251 setEventMessage(
'ErrorRecordParentingNotModified',
'errors');
1256 if ($objecttmp->element ==
'societe') {
1258 '@phan-var-force Societe $objecttmp';
1260 $result = $objecttmp->delete($objecttmp->id, $user, 1);
1262 $objecttmp->oldcopy =
dol_clone($objecttmp);
1263 $result = $objecttmp->delete($user);
1266 if (empty($result)) {
1267 $TMsg = array_merge($objecttmp->errors, $TMsg);
1268 } elseif ($result < 0) {
1269 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1276 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1282 if (empty($error)) {
1285 setEventMessages($langs->trans(
"RecordsDeleted", $nbok),
null,
'mesgs');
1286 } elseif ($nbok > 0) {
1287 setEventMessages($langs->trans(
"RecordDeleted", $nbok),
null,
'mesgs');
1289 setEventMessages($langs->trans(
"NoRecordDeleted"),
null,
'mesgs');
1293 if (!empty($TMsg)) {
1295 setEventMessages(
'', array_unique($TMsg),
'warnings');
1306if (!$error && $massaction ==
'generate_doc' && $permissiontoread) {
1308 '@phan-var-force \'Commande\'|\'CommandeFournisseur\'|\'Contrat\'|\'Expedition\'|\'ExpenseReport\'|\'Facture\'|\'FactureFournisseur\'|\'Fichinter\'|\'Project\'|\'Propal\'|\'SupplierProposal\' $objectclass';
1313 $objecttmp =
new $objectclass($db);
1315 foreach ($toselect as $toselectid) {
1316 $objecttmp->thirdparty =
null;
1317 $result = $objecttmp->fetch($toselectid);
1320 $outputlangs = $langs;
1324 $newlang =
GETPOST(
'lang_id',
'aZ09');
1326 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) {
1327 $newlang = $objecttmp->thirdparty->default_lang;
1329 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && isset($objecttmp->default_lang)) {
1330 $newlang = $objecttmp->default_lang;
1332 if (
getDolGlobalInt(
'MAIN_MULTILANGS') && empty($newlang) && empty($objecttmp->thirdparty)) {
1333 $objecttmp->fetch_thirdparty();
1334 $newlang = $objecttmp->thirdparty->default_lang;
1336 if (!empty($newlang)) {
1338 $outputlangs->setDefaultLang($newlang);
1342 $hidedetails = isset($hidedetails) ? $hidedetails : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DETAILS') ? 1 : 0);
1343 $hidedesc = isset($hidedesc) ? $hidedesc : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_DESC') ? 1 : 0);
1344 $hideref = isset($hideref) ? $hideref : (
getDolGlobalString(
'MAIN_GENERATE_DOCUMENTS_HIDE_REF') ? 1 : 0);
1345 $moreparams = isset($moreparams) ? $moreparams :
null;
1347 $result = $objecttmp->generateDocument($objecttmp->model_pdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1350 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1357 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1365 setEventMessages($langs->trans(
"RecordsGenerated", $nbok),
null,
'mesgs');
1367 setEventMessages($langs->trans(
"RecordGenerated", $nbok),
null,
'mesgs');
1375if (!$error && ($action ==
'affecttag' && $confirm ==
'yes') && $permissiontoadd) {
1379 $affecttag_type =
GETPOST(
'affecttag_type',
'alpha');
1380 if (!empty($affecttag_type)) {
1381 $affecttag_type_array = explode(
',', $affecttag_type);
1383 setEventMessage(
'CategTypeNotFound',
'errors');
1385 if (!empty($affecttag_type_array)) {
1387 require_once DOL_DOCUMENT_ROOT.
'/categories/class/categorie.class.php';
1389 $to_affecttag_type_array = array();
1390 $categ_type_array = $categ->getMapList();
1391 foreach ($categ_type_array as $categdef) {
1392 if (in_array($categdef[
'code'], $affecttag_type_array)) {
1393 $to_affecttag_type_array[] = $categdef[
'code'];
1398 if (!empty($to_affecttag_type_array)) {
1401 '@phan-var-force CommonObject $object';
1402 foreach ($to_affecttag_type_array as $categ_type) {
1403 $contcats =
GETPOST(
'contcats_' . $categ_type,
'array');
1404 foreach ($toselect as $toselectid) {
1405 $result =
$object->fetch($toselectid);
1407 $result =
$object->setCategoriesCommon($contcats, $categ_type,
false);
1424 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null);
1426 $toselect = array();
1432if (!$error && ($action ==
'updateprice' && $confirm ==
'yes') && $permissiontoadd) {
1433 '@phan-var-force Product|ProductCustomerPrice $obj';
1434 '@phan-var-force Product|ProductCustomerPrice $object';
1439 if ($pricepercentage == 0) {
1440 setEventMessages($langs->trans(
"RecordsModified", 0),
null);
1442 foreach ($toselect as $toselectid) {
1443 $result =
$object->fetch($toselectid);
1447 if (
$object->price_base_type ==
'TTC') {
1448 $newprice =
$object->price_ttc * (100 + $pricepercentage) / 100;
1449 $minprice =
$object->price_min_ttc;
1451 $newprice =
$object->price * (100 + $pricepercentage) / 100;
1452 $minprice =
$object->price_min;
1454 $res =
$object->updatePrice($newprice,
$object->price_base_type, $user,
$object->tva_tx, $minprice, 0,
$object->tva_npr, 0, 0, array(),
$object->default_vat_code);
1462 for ($level = 1; $level <= $maxlevel; $level++) {
1463 if (
$object->price_base_type ==
'TTC') {
1464 $newprice =
$object->multiprices_ttc[$level] * (100 + $pricepercentage) / 100;
1465 $minprice =
$object->multiprices_min_ttc[$level];
1467 $newprice =
$object->multiprices[$level] * (100 + $pricepercentage) / 100;
1468 $minprice =
$object->multiprices_min[$level];
1470 $res =
$object->updatePrice($newprice,
$object->price_base_type, $user,
$object->tva_tx, $minprice, $level,
$object->tva_npr, 0, 0, array(),
$object->default_vat_code);
1487 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null);
1490 $toselect = array();
1496if (!$error && ($action ==
'setsupervisor' && $confirm ==
'yes') && $permissiontoadd) {
1497 '@phan-var-force User $object';
1500 $supervisortoset =
GETPOSTINT(
'supervisortoset');
1501 if (!empty($supervisortoset)) {
1502 foreach ($toselect as $toselectid) {
1503 $result =
$object->fetch($toselectid);
1505 $object->fk_user = $supervisortoset;
1506 $res =
$object->update($user);
1519 setEventMessage(
'UserNotFound',
'errors');
1524 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null);
1526 $toselect = array();
1532if (!$error && ($action ==
'affectuser' && $confirm ==
'yes') && $permissiontoadd) {
1537 $projectrole =
GETPOST(
'projectrole');
1538 $tasksrole =
GETPOST(
'tasksrole');
1539 if (!empty($usertoaffect)) {
1540 foreach ($toselect as $toselectid) {
1541 $result =
$object->fetch($toselectid);
1543 $res =
$object->add_contact($usertoaffect, $projectrole,
'internal');
1545 $taskstatic =
new Task($db);
1546 $task_array = $taskstatic->getTasksArray(
null,
null,
$object->id, 0, 0);
1548 foreach ($task_array as $task) {
1549 $tasksToAffect =
new Task($db);
1550 $result = $tasksToAffect->fetch($task->id);
1552 $res = $tasksToAffect->add_contact($usertoaffect, $tasksrole,
'internal');
1554 setEventMessages($tasksToAffect->error, $tasksToAffect->errors,
'errors');
1569 setEventMessage(
'UserNotFound',
'errors');
1574 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null);
1576 $toselect = array();
1582if (!$error && ($massaction ==
'enable' || ($action ==
'enable' && $confirm ==
'yes')) && $permissiontoadd) {
1585 $objecttmp =
new $objectclass($db);
1587 foreach ($toselect as $toselectid) {
1588 $result = $objecttmp->fetch($toselectid);
1590 if (in_array($objecttmp->element, array(
'societe'))) {
1591 $result = $objecttmp->setStatut(1);
1594 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1601 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1609 setEventMessages($langs->trans(
"RecordsEnabled", $nbok),
null,
'mesgs');
1611 setEventMessages($langs->trans(
"RecordEnabled"),
null,
'mesgs');
1619if (!$error && ($massaction ==
'disable' || ($action ==
'disable' && $confirm ==
'yes')) && $permissiontoadd) {
1622 $objecttmp =
new $objectclass($db);
1624 foreach ($toselect as $toselectid) {
1625 $result = $objecttmp->fetch($toselectid);
1627 if (in_array($objecttmp->element, array(
'societe'))) {
1628 $result = $objecttmp->setStatut(0);
1631 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1638 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1646 setEventMessages($langs->trans(
"RecordsDisabled", $nbok),
null,
'mesgs');
1648 setEventMessages($langs->trans(
"RecordDisabled"),
null,
'mesgs');
1656if (!$error && $action ==
'confirm_edit_value_extrafields' && $confirm ==
'yes' && $permissiontoadd) {
1659 $objecttmp =
new $objectclass($db);
1661 $e->fetch_name_optionals_label($objecttmp->table_element);
1664 $extrafieldKeyToUpdate =
GETPOST(
'extrafield-key-to-update');
1667 foreach ($toselect as $toselectid) {
1669 $objecttmp =
new $objectclass($db);
1670 $result = $objecttmp->fetch($toselectid);
1673 $ret = $e->setOptionalsFromPost(
null, $objecttmp, $extrafieldKeyToUpdate);
1675 $objecttmp->insertExtraFields();
1679 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1682 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1690 setEventMessages($langs->trans(
"RecordsModified", $nbok),
null,
'mesgs');
1691 } elseif ($nbok == 1) {
1692 setEventMessages($langs->trans(
"RecordModifiedSuccessfully"),
null,
'mesgs');
1700if (!$error && ($massaction ==
'assignsalerepresentative' || ($action ==
'assignsalerepresentative' && $confirm ==
'yes')) && $permissiontoadd) {
1703 $objecttmp =
new $objectclass($db);
1706 foreach ($toselect as $toselectid) {
1707 $result = $objecttmp->fetch($toselectid);
1709 if (in_array($objecttmp->element, array(
'societe'))) {
1710 $result = $objecttmp->setSalesRep(
GETPOST(
"commercial",
"alpha"));
1713 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1720 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1728 setEventMessages($langs->trans(
"CommercialsAffected", $nbok),
null,
'mesgs');
1730 setEventMessages($langs->trans(
"CommercialAffected"),
null,
'mesgs');
1738if (!$error && ($massaction ==
'unassigncommercial' || ($action ==
'unassigncommercial' && $confirm ==
'yes')) && $permissiontoadd) {
1741 $objecttmp =
new $objectclass($db);
1744 foreach ($toselect as $toselectid) {
1745 $result = $objecttmp->fetch($toselectid);
1747 if (in_array($objecttmp->element, array(
'societe'))) {
1748 $TCommercial =
GETPOST(
"commercial",
"alpha");
1749 if (is_array($TCommercial)) {
1750 foreach ($TCommercial as $commercial) {
1751 $result = $objecttmp->del_commercial($user, $commercial);
1756 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1763 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1771 setEventMessages($langs->trans(
"CommercialsDisaffected", $nbok),
null,
'mesgs');
1773 setEventMessages($langs->trans(
"CommercialDisaffected"),
null,
'mesgs');
1781if (!$error && ($massaction ==
'approveleave' || ($action ==
'approveleave' && $confirm ==
'yes')) && $permissiontoapprove) {
1784 $objecttmp =
new $objectclass($db);
1785 '@phan-var-force Holiday $objecttmp';
1787 foreach ($toselect as $toselectid) {
1788 $result = $objecttmp->fetch($toselectid);
1791 setEventMessages($langs->trans(
'StatusOfRefMustBe', $objecttmp->ref, $langs->transnoentitiesnoconv(
'Validated')),
null,
'warnings');
1794 if ($user->id == $objecttmp->fk_validator) {
1795 $objecttmp->oldcopy =
dol_clone($objecttmp, 2);
1797 $objecttmp->date_valid =
dol_now();
1798 $objecttmp->fk_user_valid = $user->id;
1799 $objecttmp->date_approval =
dol_now();
1800 $objecttmp->fk_user_approve = $user->id;
1802 $objecttmp->statut = $objecttmp->status;
1804 $verif = $objecttmp->approve($user);
1807 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1815 $tmpUser =
new User($db);
1816 $result = $tmpUser->fetch($objecttmp->fk_user);
1819 $nbopenedday =
num_open_day($objecttmp->date_debut_gmt, $objecttmp->date_fin_gmt, 0, 1, $objecttmp->halfday, $tmpUser->country_id);
1820 $soldeActuel = $objecttmp->getCpforUser($objecttmp->fk_user, $objecttmp->fk_type);
1821 $newSolde = ($soldeActuel - $nbopenedday);
1826 $result = $objecttmp->addLogCP($user->id, $objecttmp->fk_user, $langs->transnoentitiesnoconv(
"Holidays"), $newSolde, $objecttmp->fk_type);
1829 setEventMessages(
null, $objecttmp->errors,
'errors');
1833 $result = $objecttmp->updateSoldeCP($objecttmp->fk_user, $newSolde, $objecttmp->fk_type);
1836 setEventMessages(
null, $objecttmp->errors,
'errors');
1842 $result = $objecttmp->sendApprovalEmail();
1844 setEventMessages($objecttmp->error, $objecttmp->errors,
'warnings');
1849 $langs->load(
"errors");
1850 setEventMessages($langs->trans(
'ErrorNotApproverForHoliday', $objecttmp->ref),
null,
'errors');
1853 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
1861 setEventMessages($langs->trans(
"RecordsApproved", $nbok),
null,
'mesgs');
1862 } elseif ($nbok == 1) {
1863 setEventMessages($langs->trans(
"RecordAproved"),
null,
'mesgs');
1872if (!$error && ($massaction ==
'increaseholiday' || ($action ==
'increaseholiday' && $confirm ==
'yes')) && $user->hasRight(
'holiday',
'define_holiday') && is_array($toselect)) {
1873 '@phan-var-force Holiday $holiday';
1876 $objecttmp =
new $objectclass($db);
1881 if ($nbdaysholidays <= 0) {
1882 setEventMessages($langs->trans(
"WrongAmount"),
null,
'errors');
1887 foreach ($toselect as $toselectid) {
1888 $balancecpuser = $objecttmp->getCPforUser($toselectid, $typeholiday);
1889 if (!empty($balancecpuser)) {
1890 $newnbdaysholidays = $nbdaysholidays + $balancecpuser;
1892 $newnbdaysholidays = $nbdaysholidays;
1894 $result = $holiday->addLogCP($user->id, $toselectid, $langs->transnoentitiesnoconv(
'ManualUpdate'), $newnbdaysholidays, $typeholiday);
1896 setEventMessages($holiday->error, $holiday->errors,
'errors');
1901 $objecttmp->updateSoldeCP($toselectid, $newnbdaysholidays, $typeholiday);
1905 setEventMessages($langs->trans(
"ErrorUpdatingUsersCP"),
null,
'errors');
1914 setEventMessages($langs->trans(
"HolidayRecordsIncreased", $nbok),
null,
'mesgs');
1915 } elseif ($nbok == 1) {
1916 setEventMessages($langs->trans(
"HolidayRecordIncreased"),
null,
'mesgs');
1919 $toselect = array();
1926if (!$error && ($massaction ==
'clonetasks' || ($action ==
'clonetasks' && $confirm ==
'yes'))) {
1929 include_once DOL_DOCUMENT_ROOT.
'/projet/class/task.class.php';
1931 $origin_task =
new Task($db);
1932 $clone_task =
new Task($db);
1933 $newproject =
new Project($db);
1937 $iscontactofnewproject = 0;
1938 if (empty($newproject->public)) {
1939 $tmps = $newproject->getProjectsAuthorizedForUser($user, 0, 1, 0,
'(fk_statut:=:1)');
1940 $tmparray = explode(
',', $tmps);
1941 if (in_array($newproject->id, $tmparray)) {
1942 $iscontactofnewproject = 1;
1947 $permisstiontoadd =
false;
1948 if ($user->hasRight(
'project',
'all',
'creer') || ($user->hasRight(
'project',
'creer') && ($newproject->public || $iscontactofnewproject))) {
1949 $permisstiontoadd =
true;
1952 if ($permisstiontoadd) {
1953 $taskidsmapping = array();
1954 $clonedtaskoldparent = array();
1959 $authorizedsourceprojects =
null;
1960 if (!$user->hasRight(
'projet',
'all',
'lire')) {
1961 $sourceprojectstatic =
new Project($db);
1962 $tmps = $sourceprojectstatic->getProjectsAuthorizedForUser($user, 0, 1, 0);
1963 $authorizedsourceprojects = explode(
',', $tmps);
1966 foreach (
GETPOST(
'selected') as $task) {
1967 if ($origin_task->fetch($task,
'', 0) <= 0) {
1972 if (is_array($authorizedsourceprojects) && !in_array($origin_task->fk_project, $authorizedsourceprojects)) {
1973 setEventMessages($langs->trans(
'NotEnoughPermissions'),
null,
'errors');
1981 require_once DOL_DOCUMENT_ROOT .
"/core/modules/project/task/" .
getDolGlobalString(
'PROJECT_TASK_ADDON') .
'.php';
1982 $modTask =
new $classnamemodtask();
1983 '@phan-var-force ModeleNumRefTask $modTask';
1985 $defaultref = $modTask->getNextValue(
null, $clone_task);
1989 $clone_task->fk_project =
GETPOSTINT(
'projectid');
1990 $clone_task->ref = $defaultref;
1991 $clone_task->label = $origin_task->label;
1992 $clone_task->description = $origin_task->description;
1993 $clone_task->planned_workload = $origin_task->planned_workload;
1994 $clone_task->fk_task_parent = $origin_task->fk_task_parent;
1995 $clone_task->date_c =
dol_now();
1996 $clone_task->date_start = $origin_task->date_start;
1997 $clone_task->date_end = $origin_task->date_end;
1998 $clone_task->progress = $origin_task->progress;
2001 $ret = $extrafields->setOptionalsFromPost(
null, $clone_task);
2003 $taskid = $clone_task->create($user);
2006 $result = $clone_task->add_contact(
GETPOSTINT(
"userid"),
'TASKEXECUTIVE',
'internal');
2007 $taskidsmapping[$task] = $taskid;
2008 $clonedtaskoldparent[$taskid] = $origin_task->fk_task_parent;
2011 if ($db->lasterrno() ==
'DB_ERROR_RECORD_ALREADY_EXISTS') {
2012 $langs->load(
"projects");
2013 setEventMessages($langs->trans(
'NewTaskRefSuggested'),
null,
'warnings');
2014 $duplicate_code_error =
true;
2016 setEventMessages($clone_task->error, $clone_task->errors,
'errors');
2028 foreach ($clonedtaskoldparent as $newtaskid => $oldparentid) {
2029 if (empty($oldparentid)) {
2032 $newparentid = isset($taskidsmapping[$oldparentid]) ? $taskidsmapping[$oldparentid] : 0;
2033 $remaptask =
new Task($db);
2034 if ($remaptask->fetch($newtaskid) > 0 && $remaptask->fk_task_parent != $newparentid) {
2035 $remaptask->fk_task_parent = $newparentid;
2036 if ($remaptask->update($user) < 0) {
2037 setEventMessages($remaptask->error, $remaptask->errors,
'errors');
2045 setEventMessages($langs->trans(
'NumberOfTasksCloned', $num),
null,
'mesgs');
2046 header(
"Location: ".DOL_URL_ROOT.
'/projet/tasks.php?id='.
GETPOSTINT(
'projectid'));
2050 setEventMessages($langs->trans(
'NotEnoughPermissions'),
null,
'errors');
2054if (!$error && $action ==
'createcreditnote' && $permissiontoadd) {
2057 setEventMessages($langs->trans(
'CreditNoteNotCreatedStockCalculateOnBillEnabled'),
null,
'errors');
2058 header(
"Location: ".DOL_URL_ROOT.
'/compta/facture/list.php?mainmenu=compta&leftmenu=facture');
2062 $objecttmp =
new $objectclass($db);
2063 if ($objecttmp->element ==
'facture' || $objecttmp->element ==
'invoice') {
2068 $unique_arr = array_unique($toselect);
2069 foreach ($unique_arr as $toselectid) {
2070 $sourceinvoice = $toselectid;
2071 $result = $objecttmp->fetch($sourceinvoice);
2075 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
2076 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedSourceInvoiceNotFound', $sourceinvoice);
2081 $isSupportedType =
false;
2083 $isSupportedType =
true;
2086 $isSupportedType =
true;
2089 $isSupportedType =
true;
2092 if (!$isSupportedType) {
2101 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedInvoiceTypeNotSupported', $objecttmp->ref, $listtype[$objecttmp->type]);
2107 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedInvoiceNotValidated', $objecttmp->ref);
2112 $totalpaid = $objecttmp->getSommePaiement();
2113 $totalcreditnotes = $objecttmp->getSumCreditNotesUsed();
2114 $totaldeposits = $objecttmp->getSumDepositsUsed();
2115 if ($totalpaid > 0) {
2116 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedPaymentAlreadyDone', $objecttmp->ref);
2119 if ($totalcreditnotes > 0) {
2120 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedCreditNoteAlreadyUsed', $objecttmp->ref);
2123 if ($totaldeposits > 0) {
2124 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedDepositAlreadyUsed', $objecttmp->ref);
2132 $object->entity = $objecttmp->entity;
2133 $object->socid = $objecttmp->socid;
2134 $object->subtype = $objecttmp->subtype;
2138 $object->ref_client = $objecttmp->ref_client;
2139 $object->ref_customer = $objecttmp->ref_customer;
2140 $object->fk_project = $objecttmp->fk_project;
2141 $object->cond_reglement_id = 0;
2142 $object->fk_account = $objecttmp->fk_account;
2143 $object->fk_incoterms = $objecttmp->fk_incoterms;
2144 $object->location_incoterms = $objecttmp->location_incoterms;
2145 $object->multicurrency_code = $objecttmp->multicurrency_code;
2146 $object->multicurrency_tx = $objecttmp->multicurrency_tx;
2148 $object->fk_facture_source = $sourceinvoice;
2152 if ($objecttmp->isSituationInvoice()) {
2153 $object->situation_counter = $objecttmp->situation_counter;
2154 $object->situation_cycle_ref = $objecttmp->situation_cycle_ref;
2155 $objecttmp->fetchPreviousNextSituationInvoice();
2162 $TMsg[] = $langs->trans(
'CreditNoteNotCreated', $objecttmp->ref);
2166 $facture_source = $objecttmp;
2169 $object->copy_linked_contact($objecttmp,
'internal');
2170 $object->copy_linked_contact($objecttmp,
'external');
2173 if (!empty($facture_source->lines)) {
2174 $fk_parent_line = 0;
2176 foreach ($facture_source->lines as $line) {
2178 if (method_exists($line,
'fetch_optionals')) {
2180 $line->fetch_optionals();
2184 if (($line->product_type != 9 && empty($line->fk_parent_line)) || $line->product_type == 9) {
2185 $fk_parent_line = 0;
2188 if ($facture_source->isSituationInvoice()) {
2189 $source_fk_prev_id = $line->fk_prev_id;
2190 $line->fk_prev_id = $line->id;
2192 if (!empty($facture_source->tab_previous_situation_invoice)) {
2195 $tab_jumped_credit_notes = array();
2196 $lineIndex = count($facture_source->tab_previous_situation_invoice) - 1;
2197 $searchPreviousInvoice =
true;
2198 while ($searchPreviousInvoice) {
2199 if ($facture_source->tab_previous_situation_invoice[$lineIndex]->type ==
Facture::TYPE_SITUATION || $lineIndex < 1) {
2200 $searchPreviousInvoice =
false;
2204 $tab_jumped_credit_notes[$lineIndex] = $facture_source->tab_previous_situation_invoice[$lineIndex]->id;
2210 $maxPrevSituationPercent = 0;
2211 foreach ($facture_source->tab_previous_situation_invoice[$lineIndex]->lines as $prevLine) {
2212 if ($prevLine->id == $source_fk_prev_id) {
2213 $maxPrevSituationPercent = max($maxPrevSituationPercent, $prevLine->situation_percent);
2216 $line->total_ht -= $prevLine->total_ht;
2217 $line->total_tva -= $prevLine->total_tva;
2218 $line->total_ttc -= $prevLine->total_ttc;
2219 $line->total_localtax1 -= $prevLine->total_localtax1;
2220 $line->total_localtax2 -= $prevLine->total_localtax2;
2222 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
2223 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
2224 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
2225 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
2230 $line->situation_percent = $maxPrevSituationPercent - $line->situation_percent;
2235 $maxPrevSituationPercent = 0;
2236 foreach ($tab_jumped_credit_notes as $index => $creditnoteid) {
2237 foreach ($facture_source->tab_previous_situation_invoice[$index]->lines as $prevLine) {
2238 if ($prevLine->fk_prev_id == $source_fk_prev_id) {
2239 $maxPrevSituationPercent = $prevLine->situation_percent;
2241 $line->total_ht -= $prevLine->total_ht;
2242 $line->total_tva -= $prevLine->total_tva;
2243 $line->total_ttc -= $prevLine->total_ttc;
2244 $line->total_localtax1 -= $prevLine->total_localtax1;
2245 $line->total_localtax2 -= $prevLine->total_localtax2;
2247 $line->multicurrency_subprice -= $prevLine->multicurrency_subprice;
2248 $line->multicurrency_total_ht -= $prevLine->multicurrency_total_ht;
2249 $line->multicurrency_total_tva -= $prevLine->multicurrency_total_tva;
2250 $line->multicurrency_total_ttc -= $prevLine->multicurrency_total_ttc;
2256 $line->situation_percent += $maxPrevSituationPercent;
2262 $line->fk_facture =
$object->id;
2263 $line->fk_parent_line = $fk_parent_line;
2265 $line->subprice = -$line->subprice;
2267 $line->total_ht = -$line->total_ht;
2268 $line->total_tva = -$line->total_tva;
2269 $line->total_ttc = -$line->total_ttc;
2270 $line->total_localtax1 = -$line->total_localtax1;
2271 $line->total_localtax2 = -$line->total_localtax2;
2273 $line->multicurrency_subprice = -$line->multicurrency_subprice;
2274 $line->multicurrency_total_ht = -$line->multicurrency_total_ht;
2275 $line->multicurrency_total_tva = -$line->multicurrency_total_tva;
2276 $line->multicurrency_total_ttc = -$line->multicurrency_total_ttc;
2278 $line->context[
'createcreditnotefrominvoice'] = 1;
2279 $result = $line->insert(0, 1);
2284 if ($result > 0 && $line->product_type == 9) {
2285 $fk_parent_line = $result;
2293 if (!empty(
$object->fk_facture_source) &&
$id > 0) {
2294 $facture_source->fetch(
$object->fk_facture_source);
2295 $facture_source->fetchObjectLinked();
2297 if (!empty($facture_source->linkedObjectsIds)) {
2298 foreach ($facture_source->linkedObjectsIds as $sourcetype => $TIds) {
2299 $object->add_object_linked($sourcetype, current($TIds));
2305 $result =
$object->validate($user);
2308 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnValidation', $objecttmp->ref);
2314 $outputlangs = $langs;
2317 $newlang =
GETPOST(
'lang_id',
'aZ09');
2320 $newlang =
$object->thirdparty->default_lang;
2322 if (!empty($newlang)) {
2324 $outputlangs->setDefaultLang($newlang);
2325 $outputlangs->load(
'products');
2331 $result =
$object->generateDocument($model, $outputlangs, (
int) $hidedetails, (
int) $hidedesc, (
int) $hideref);
2343 $result = $discountcheck->fetch(0,
$object->id);
2346 if (empty($discountcheck->id)) {
2351 $amount_ht = $amount_tva = $amount_ttc = array();
2352 $multicurrency_amount_ht = $multicurrency_amount_tva = $multicurrency_amount_ttc = array();
2356 foreach (
$object->lines as $line) {
2357 if ($line->product_type < 9 && $line->total_ht != 0) {
2358 $keyforvatrate = $line->tva_tx.($line->vat_src_code ?
' ('.$line->vat_src_code.
')' :
'');
2360 if (!isset($amount_ht[$keyforvatrate])) {
2361 $amount_ht[$keyforvatrate] = 0;
2363 $amount_ht[$keyforvatrate] += $line->total_ht;
2364 if (!isset($amount_tva[$keyforvatrate])) {
2365 $amount_tva[$keyforvatrate] = 0;
2367 $amount_tva[$keyforvatrate] += $line->total_tva;
2368 if (!isset($amount_ttc[$keyforvatrate])) {
2369 $amount_ttc[$keyforvatrate] = 0;
2371 $amount_ttc[$keyforvatrate] += $line->total_ttc;
2372 if (!isset($multicurrency_amount_ht[$keyforvatrate])) {
2373 $multicurrency_amount_ht[$keyforvatrate] = 0;
2375 $multicurrency_amount_ht[$keyforvatrate] += $line->multicurrency_total_ht;
2376 if (!isset($multicurrency_amount_tva[$keyforvatrate])) {
2377 $multicurrency_amount_tva[$keyforvatrate] = 0;
2379 $multicurrency_amount_tva[$keyforvatrate] += $line->multicurrency_total_tva;
2380 if (!isset($multicurrency_amount_ttc[$keyforvatrate])) {
2381 $multicurrency_amount_ttc[$keyforvatrate] = 0;
2383 $multicurrency_amount_ttc[$keyforvatrate] += $line->multicurrency_total_ttc;
2390 $discount->description =
'(CREDIT_NOTE)';
2391 $discount->fk_soc =
$object->socid;
2392 $discount->socid =
$object->socid;
2393 $discount->socid =
$object->socid;
2394 $discount->fk_facture_source =
$object->id;
2399 foreach ($amount_ht as $tva_tx => $xxx) {
2400 $discount->amount_ht = -((float) $amount_ht[$tva_tx]);
2401 $discount->amount_tva = -((float) $amount_tva[$tva_tx]);
2402 $discount->amount_ttc = -((float) $amount_ttc[$tva_tx]);
2403 $discount->total_ht = -((float) $amount_ht[$tva_tx]);
2404 $discount->total_tva = -((float) $amount_tva[$tva_tx]);
2405 $discount->total_ttc = -((float) $amount_ttc[$tva_tx]);
2406 $discount->multicurrency_amount_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
2407 $discount->multicurrency_amount_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
2408 $discount->multicurrency_amount_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
2409 $discount->multicurrency_total_ht = -((float) $multicurrency_amount_ht[$tva_tx]);
2410 $discount->multicurrency_total_tva = -((float) $multicurrency_amount_tva[$tva_tx]);
2411 $discount->multicurrency_total_ttc = -((float) $multicurrency_amount_ttc[$tva_tx]);
2416 if (preg_match(
'/\((.*)\)/', $tva_tx, $reg)) {
2417 $vat_src_code = $reg[1];
2418 $tva_tx = preg_replace(
'/\s*\(.*\)/',
'', $tva_tx);
2421 $discount->tva_tx = abs((
float) $tva_tx);
2422 $discount->vat_src_code = $vat_src_code;
2424 $id_discount = $discount->create($user);
2425 if ($id_discount < 0) {
2431 if (empty($error) && $id_discount > 0) {
2433 $result =
$object->setPaid($user);
2439 $discount->fetch($id_discount);
2440 $result = $discount->link_to_invoice(0,
$object->fk_facture_source);
2442 setEventMessages($discount->error, $discount->errors,
'errors');
2443 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnDiscountLink', $objecttmp->ref);
2449 $objecttmp->fetch($objecttmp->id);
2450 if ($objecttmp->getRemainToPay(0) == 0) {
2451 $result = $objecttmp->setPaid($user);
2453 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
2454 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnSetPaidSourceInvoice', $objecttmp->ref);
2459 $outputlangs = $langs;
2462 $newlang =
GETPOST(
'lang_id',
'aZ09');
2465 $objecttmp->fetch_thirdparty();
2466 $newlang = $objecttmp->thirdparty->default_lang;
2468 if (!empty($newlang)) {
2470 $outputlangs->setDefaultLang($newlang);
2472 $ret = $objecttmp->fetch($objecttmp->id);
2474 $result = $objecttmp->generateDocument($objecttmp->model_pdf, $outputlangs, (
int) $hidedetails, (
int) $hidedesc, (
int) $hideref);
2476 setEventMessages($objecttmp->error, $objecttmp->errors,
'errors');
2482 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnSourceInvoiceNotFullyPaidAfterDiscount', $objecttmp->ref);
2488 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnSetPaid', $objecttmp->ref);
2493 setEventMessages($discount->error, $discount->errors,
'errors');
2494 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedErrorOnDiscount', $objecttmp->ref);
2499 $TMsg[] = $langs->trans(
'CreditNoteNotCreatedAlreadyConverted', $objecttmp->ref);
2507 $TMsg[] = $langs->trans(
'CreditNoteCreated',
$object->ref, $objecttmp->ref);
2512 foreach ($TMsg as $msg) {
2513 setEventMessages($msg,
null,
'warnings');
2518 setEventMessages($langs->trans(
'CreditNotesCreated', $nbok),
null,
'mesgs');
2521 $toselect = array();
2522 header(
"Location: ".DOL_URL_ROOT.
'/compta/facture/list.php?mainmenu=compta&leftmenu=facture');
2525 setEventMessages($langs->trans(
'ThisMassActionIsOnlyForInvoices'),
null,
'errors');
2526 header(
"Location: ".DOL_URL_ROOT.
'/compta/facture/list.php?mainmenu=compta&leftmenu=facture');
2531if (empty($toselect)) {
2534$parameters[
'toselect'] = &$toselect;
2535$parameters[
'uploaddir'] = $uploaddir;
2536$parameters[
'massaction'] = $massaction;
2537$parameters[
'diroutputmassaction'] = isset($diroutputmassaction) ? $diroutputmassaction :
null;
2540$reshook = $hookmanager->executeHooks(
'doMassActions', $parameters,
$object, $action);
2542 setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
$id
Support class for third parties, contacts, members, users or resources.
if(! $sortfield) if(! $sortorder) $object
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
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.
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.