40 if (empty($objectclass) || empty($uploaddir))
42 dol_print_error(null,
'include of actions_massactions.inc.php is done but var $objectclass or $uploaddir was not defined');
47 if (!empty($permtoread) && empty($permissiontoread)) $permissiontoread = $permtoread;
48 if (!empty($permtocreate) && empty($permissiontoadd)) $permissiontoadd = $permtocreate;
49 if (!empty($permtodelete) && empty($permissiontodelete)) $permissiontodelete = $permtodelete;
53 $maxformassaction = (empty($conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS) ? 1000 : $conf->global->MAIN_LIMIT_FOR_MASS_ACTIONS);
54 if (!empty($massaction) && is_array($toselect) && count($toselect) < 1)
59 if (!$error && is_array($toselect) && count($toselect) > $maxformassaction)
61 setEventMessages($langs->trans(
'TooManyRecordForMassAction', $maxformassaction), null,
'errors');
65 if (!$error && $massaction ==
'confirm_presend' && !
GETPOST(
'sendmail'))
67 $massaction =
'presend';
69 if (!$error && $massaction ==
'confirm_presend')
74 $langs->load(
"mails");
75 include_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
77 $listofobjectid = array();
78 $listofobjectthirdparties = array();
79 $listofobjectcontacts = array();
80 $listofobjectref = array();
81 $contactidtosend = array();
82 $attachedfilesThirdpartyObj = array();
83 $oneemailperrecipient = (
GETPOST(
'oneemailperrecipient') ==
'on' ? 1 : 0);
89 $objecttmp =
new $objectclass($db);
90 if ($objecttmp->element ==
'expensereport') $thirdparty =
new User($db);
91 if ($objecttmp->element ==
'holiday') $thirdparty =
new User($db);
93 foreach ($toselect as $toselectid)
95 $objecttmp =
new $objectclass($db);
96 $result = $objecttmp->fetch($toselectid);
99 $listofobjectid[$toselectid] = $toselectid;
101 $thirdpartyid = ($objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid);
102 if ($objecttmp->element ==
'societe') $thirdpartyid = $objecttmp->id;
103 if ($objecttmp->element ==
'expensereport') $thirdpartyid = $objecttmp->fk_user_author;
104 if ($objecttmp->element ==
'holiday') $thirdpartyid = $objecttmp->fk_user;
105 if (empty($thirdpartyid)) $thirdpartyid = 0;
107 if ($objectclass ==
'Facture') {
108 $tmparraycontact = array();
109 $tmparraycontact = $objecttmp->liste_contact(-1,
'external', 0,
'BILLING');
110 if (is_array($tmparraycontact) && count($tmparraycontact) > 0) {
111 foreach ($tmparraycontact as $data_email) {
112 $listofobjectcontacts[$toselectid][$data_email[
'id']] = $data_email[
'email'];
117 $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid;
118 $listofobjectref[$thirdpartyid][$toselectid] = $objecttmp;
124 if (
GETPOST(
'fromtype',
'alpha') ===
'user' && empty($user->email))
128 $massaction =
'presend';
131 $receiver = $_POST[
'receiver'];
132 if (!is_array($receiver))
134 if (empty($receiver) || $receiver ==
'-1') $receiver = array();
135 else $receiver = array($receiver);
137 if (!trim($_POST[
'sendto']) && count($receiver) == 0 && count($listofobjectthirdparties) == 1)
140 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Recipient")), null,
'warnings');
141 $massaction =
'presend';
144 if (!
GETPOST(
'subject',
'restricthtml'))
147 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"MailTopic")), null,
'warnings');
148 $massaction =
'presend';
154 foreach ($listofobjectthirdparties as $thirdpartyid)
156 $result = $thirdparty->fetch($thirdpartyid);
170 if (trim($_POST[
'sendto']))
173 $tmparray[] = trim($_POST[
'sendto']);
175 if (count($receiver) > 0)
177 foreach ($receiver as $key=>$val)
180 if ($val ==
'thirdparty')
182 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
183 } elseif ($val && method_exists($thirdparty,
'contact_get_property'))
185 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
190 $sendto = implode(
',', $tmparray);
193 $receivercc = $_POST[
'receivercc'];
194 if (!is_array($receivercc))
196 if ($receivercc ==
'-1') $receivercc = array();
197 else $receivercc = array($receivercc);
200 if (trim($_POST[
'sendtocc']))
202 $tmparray[] = trim($_POST[
'sendtocc']);
204 if (count($receivercc) > 0)
206 foreach ($receivercc as $key=>$val)
209 if ($val ==
'thirdparty')
211 $tmparray[] = $thirdparty->name.
' <'.$thirdparty->email.
'>';
214 $tmparray[] = $thirdparty->contact_get_property((
int) $val,
'email');
219 $sendtocc = implode(
',', $tmparray);
222 $listofqualifiedobj = array();
223 $listofqualifiedref = array();
224 $thirdpartywithoutemail = array();
226 foreach ($listofobjectref[$thirdpartyid] as $objectid => $objectobj)
231 $langs->load(
"errors");
233 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyProposalNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
238 $langs->load(
"errors");
240 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyOrderNotDraftCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
245 $langs->load(
"errors");
247 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyInvoiceValidatedCanBeSentInMassAction', $objectobj->ref).
'</div><br>';
254 if ($objectobj->element ==
'societe')
256 $sendto = $objectobj->email;
257 } elseif ($objectobj->element ==
'expensereport')
259 $fuser =
new User($db);
260 $fuser->fetch($objectobj->fk_user_author);
261 $sendto = $fuser->email;
262 } elseif ($objectobj->element ==
'holiday')
264 $fuser =
new User($db);
265 $fuser->fetch($objectobj->fk_user);
266 $sendto = $fuser->email;
267 } elseif ($objectobj->element ==
'facture' && !empty($listofobjectcontacts[$objectid]))
269 $emails_to_sends = array();
270 $objectobj->fetch_thirdparty();
271 $contactidtosend = array();
272 foreach ($listofobjectcontacts[$objectid] as $contactemailid => $contactemailemail) {
273 $emails_to_sends[] = $objectobj->thirdparty->contact_get_property($contactemailid,
'email');
274 if (!in_array($contactemailid, $contactidtosend)) {
275 $contactidtosend[] = $contactemailid;
278 if (count($emails_to_sends) > 0) {
279 $sendto = implode(
',', $emails_to_sends);
282 $objectobj->fetch_thirdparty();
283 $sendto = $objectobj->thirdparty->email;
289 if ($objectobj->element ==
'societe') {
290 $objectobj->thirdparty = $objectobj;
295 if (empty($thirdpartywithoutemail[$objectobj->thirdparty->id]))
297 $resaction .=
'<div class="error">'.$langs->trans(
'NoRecipientEmail', $objectobj->thirdparty->name).
'</div><br>';
299 dol_syslog(
'No recipient for thirdparty: '.$objectobj->thirdparty->name, LOG_WARNING);
300 $thirdpartywithoutemail[$objectobj->thirdparty->id] = 1;
304 if ($_POST[
'addmaindocfile'])
312 $filedir = $uploaddir.
'/'.$subdir.dol_sanitizeFileName($objectobj->ref);
313 $file = $filedir.
'/'.$filename;
316 if ($objectobj->element ==
'invoice_supplier')
318 $fileparams =
dol_most_recent_file($uploaddir.
'/'.
get_exdir($objectobj->id, 2, 0, 0, $objectobj, $objectobj->element).$objectobj->ref, preg_quote($objectobj->ref,
'/').
'([^\-])+');
319 $file = $fileparams[
'fullname'];
327 $attachedfilesThirdpartyObj[$thirdpartyid][$objectid] = array(
328 'paths'=>array($file),
329 'names'=>array($filename),
330 'mimes'=>array($mime)
334 $langs->load(
"errors");
335 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorCantReadFile', $file).
'</div><br>';
336 dol_syslog(
'Failed to read file: '.$file, LOG_WARNING);
342 $listofqualifiedobj[$objectid] = $objectobj;
343 $listofqualifiedref[$objectid] = $objectobj->ref;
350 if (count($listofqualifiedobj) > 0)
352 $langs->load(
"commercial");
355 $fromtype =
GETPOST(
'fromtype');
356 if ($fromtype ===
'user') {
357 $from = $user->getFullName($langs).
' <'.$user->email.
'>';
358 } elseif ($fromtype ===
'company') {
359 $from = $conf->global->MAIN_INFO_SOCIETE_NOM.
' <'.$conf->global->MAIN_INFO_SOCIETE_MAIL.
'>';
360 } elseif (preg_match(
'/user_aliases_(\d+)/', $fromtype, $reg)) {
361 $tmp = explode(
',', $user->email_aliases);
362 $from = trim($tmp[($reg[1] - 1)]);
363 } elseif (preg_match(
'/global_aliases_(\d+)/', $fromtype, $reg)) {
364 $tmp = explode(
',', $conf->global->MAIN_INFO_SOCIETE_MAIL_ALIASES);
365 $from = trim($tmp[($reg[1] - 1)]);
366 } elseif (preg_match(
'/senderprofile_(\d+)_(\d+)/', $fromtype, $reg)) {
367 $sql =
'SELECT rowid, label, email FROM '.MAIN_DB_PREFIX.
'c_email_senderprofile WHERE rowid = '.(int) $reg[1];
368 $resql = $db->query($sql);
369 $obj = $db->fetch_object(
$resql);
372 $from = $obj->label.
' <'.$obj->email.
'>';
375 $from = $_POST[
'fromname'].
' <'.$_POST[
'frommail'].
'>';
379 $subject =
GETPOST(
'subject',
'restricthtml');
380 $message =
GETPOST(
'message',
'restricthtml');
382 $sendtobcc =
GETPOST(
'sendtoccc');
383 if ($objectclass ==
'Propal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO) ?
'' : (($sendtobcc ?
", " :
"").$conf->global->MAIN_MAIL_AUTOCOPY_PROPOSAL_TO));
384 if ($objectclass ==
'Commande') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO) ?
'' : (($sendtobcc ?
", " :
"").$conf->global->MAIN_MAIL_AUTOCOPY_ORDER_TO));
385 if ($objectclass ==
'Facture') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO) ?
'' : (($sendtobcc ?
", " :
"").$conf->global->MAIN_MAIL_AUTOCOPY_INVOICE_TO));
386 if ($objectclass ==
'Supplier_Proposal') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO) ?
'' : (($sendtobcc ?
", " :
"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_PROPOSAL_TO));
387 if ($objectclass ==
'CommandeFournisseur') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO) ?
'' : (($sendtobcc ?
", " :
"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_ORDER_TO));
388 if ($objectclass ==
'FactureFournisseur') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO) ?
'' : (($sendtobcc ?
", " :
"").$conf->global->MAIN_MAIL_AUTOCOPY_SUPPLIER_INVOICE_TO));
389 if ($objectclass ==
'Project') $sendtobcc .= (empty($conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO) ?
'' : (($sendtobcc ?
", " :
"").$conf->global->MAIN_MAIL_AUTOCOPY_PROJECT_TO));
393 $looparray = array();
394 if (!$oneemailperrecipient)
396 $looparray = $listofqualifiedobj;
397 foreach ($looparray as $key => $objecttmp)
399 $looparray[$key]->thirdparty = $thirdparty;
402 $objectforloop =
new $objectclass($db);
403 $objectforloop->thirdparty = $thirdparty;
404 $looparray[0] = $objectforloop;
407 dol_syslog(
"We have set an array of ".count($looparray).
" emails to send. oneemailperrecipient=".$oneemailperrecipient);
409 foreach ($looparray as $objectid => $objecttmp)
412 if (!empty($conf->projet->enabled) && method_exists($objecttmp,
'fetch_projet') && is_null($objecttmp->project))
414 $objecttmp->fetch_projet();
417 $substitutionarray[
'__ID__'] = ($oneemailperrecipient ? join(
', ', array_keys($listofqualifiedobj)) : $objecttmp->id);
418 $substitutionarray[
'__REF__'] = ($oneemailperrecipient ? join(
', ', $listofqualifiedref) : $objecttmp->ref);
419 $substitutionarray[
'__EMAIL__'] = $thirdparty->email;
420 $substitutionarray[
'__CHECK_READ__'] =
'<img src="'.DOL_MAIN_URL_ROOT.
'/public/emailing/mailing-read.php?tag='.$thirdparty->tag.
'&securitykey='.urlencode($conf->global->MAILING_EMAIL_UNSUBSCRIBE_KEY).
'" width="1" height="1" style="width:1px;height:1px" border="0"/>';
422 $parameters = array(
'mode'=>
'formemail');
424 if (!empty($listofobjectthirdparties)) {
425 $parameters[
'listofobjectthirdparties'] = $listofobjectthirdparties;
427 if (!empty($listofobjectref)) {
428 $parameters[
'listofobjectref'] = $listofobjectref;
436 $attachedfiles = array(
'paths'=>array(),
'names'=>array(),
'mimes'=>array());
437 if ($oneemailperrecipient)
440 if (is_array($attachedfilesThirdpartyObj[$thirdparty->id]) && count($attachedfilesThirdpartyObj[$thirdparty->id]))
442 foreach ($attachedfilesThirdpartyObj[$thirdparty->id] as $keyObjId => $objAttachedFiles) {
444 $attachedfiles = array(
445 'paths'=>array_merge($attachedfiles[
'paths'], $objAttachedFiles[
'paths']),
446 'names'=>array_merge($attachedfiles[
'names'], $objAttachedFiles[
'names']),
447 'mimes'=>array_merge($attachedfiles[
'mimes'], $objAttachedFiles[
'mimes'])
451 } elseif (!empty($attachedfilesThirdpartyObj[$thirdparty->id][$objectid])) {
454 $attachedfiles = $attachedfilesThirdpartyObj[$thirdparty->id][$objectid];
457 $filepath = $attachedfiles[
'paths'];
458 $filename = $attachedfiles[
'names'];
459 $mimetype = $attachedfiles[
'mimes'];
462 if ($oneemailperrecipient)
464 $trackid =
'thi'.$thirdparty->id;
465 if ($objecttmp->element ==
'expensereport') $trackid =
'use'.$thirdparty->id;
466 if ($objecttmp->element ==
'holiday') $trackid =
'use'.$thirdparty->id;
468 $trackid = strtolower(get_class($objecttmp));
469 if (get_class($objecttmp) ==
'Contrat') $trackid =
'con';
470 if (get_class($objecttmp) ==
'Propal') $trackid =
'pro';
471 if (get_class($objecttmp) ==
'Commande') $trackid =
'ord';
472 if (get_class($objecttmp) ==
'Facture') $trackid =
'inv';
473 if (get_class($objecttmp) ==
'Supplier_Proposal') $trackid =
'spr';
474 if (get_class($objecttmp) ==
'CommandeFournisseur') $trackid =
'sor';
475 if (get_class($objecttmp) ==
'FactureFournisseur') $trackid =
'sin';
477 $trackid .= $objecttmp->id;
483 if (empty($sendcontext)) $sendcontext =
'standard';
486 require_once DOL_DOCUMENT_ROOT.
'/core/class/CMailFile.class.php';
487 $mailfile =
new CMailFile($subjectreplaced, $sendto, $from, $messagereplaced, $filepath, $mimetype, $filename, $sendtocc, $sendtobcc, $deliveryreceipt, -1,
'',
'', $trackid,
'', $sendcontext);
488 if ($mailfile->error)
490 $resaction .=
'<div class="error">'.$mailfile->error.
'</div>';
492 $result = $mailfile->sendfile();
495 $resaction .= $langs->trans(
'MailSuccessfulySent', $mailfile->getValidAddress($from, 2), $mailfile->getValidAddress($sendto, 2)).
'<br>';
500 foreach ($listofqualifiedobj as $objid2 => $objectobj2)
502 if ((!$oneemailperrecipient) && $objid2 != $objectid)
continue;
504 dol_syslog(
"Try to insert email event into agenda for objid=".$objid2.
" => objectobj=".get_class($objectobj2));
513 $actionmsg = $langs->transnoentities(
'MailSentBy').
' '.$from.
' '.$langs->transnoentities(
'To').
' '.$sendto;
516 if ($sendtocc) $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'Bcc').
": ".$sendtocc);
517 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'MailTopic').
": ".$subjectreplaced);
518 $actionmsg =
dol_concatdesc($actionmsg, $langs->transnoentities(
'TextUsedInTheMessageBody').
":");
524 $objectobj2->sendtoid = (empty($contactidtosend) ? 0 : $contactidtosend);
525 $objectobj2->actionmsg = $actionmsg;
526 $objectobj2->actionmsg2 = $actionmsg2;
527 $objectobj2->fk_element = $objid2;
528 $objectobj2->elementtype = $objectobj2->element;
530 $triggername = strtoupper(get_class($objectobj2)).
'_SENTBYMAIL';
531 if ($triggername ==
'SOCIETE_SENTBYMAIL') $triggername =
'COMPANY_SENTBYMAIL';
532 if ($triggername ==
'CONTRAT_SENTBYMAIL') $triggername =
'CONTRACT_SENTBYMAIL';
533 if ($triggername ==
'COMMANDE_SENTBYMAIL') $triggername =
'ORDER_SENTBYMAIL';
534 if ($triggername ==
'FACTURE_SENTBYMAIL') $triggername =
'BILL_SENTBYMAIL';
535 if ($triggername ==
'EXPEDITION_SENTBYMAIL') $triggername =
'SHIPPING_SENTBYMAIL';
536 if ($triggername ==
'COMMANDEFOURNISSEUR_SENTBYMAIL') $triggername =
'ORDER_SUPPLIER_SENTBYMAIL';
537 if ($triggername ==
'FACTUREFOURNISSEUR_SENTBYMAIL') $triggername =
'BILL_SUPPLIER_SENTBYMAIL';
538 if ($triggername ==
'SUPPLIERPROPOSAL_SENTBYMAIL') $triggername =
'PROPOSAL_SUPPLIER_SENTBYMAIL';
540 if (!empty($triggername))
543 $result = $objectobj2->call_trigger($triggername, $user);
544 if ($result < 0) $error++;
550 dol_syslog(
"Error in trigger ".$triggername.
' '.$db->lasterror(), LOG_ERR);
557 $langs->load(
"other");
558 if ($mailfile->error)
560 $resaction .= $langs->trans(
'ErrorFailedToSendMail', $from, $sendto);
561 $resaction .=
'<br><div class="error">'.$mailfile->error.
'</div>';
563 $resaction .=
'<div class="warning">No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS</div>';
571 $resaction .= ($resaction ?
'<br>' : $resaction);
572 $resaction .=
'<strong>'.$langs->trans(
"ResultOfMailSending").
':</strong><br>'.
"\n";
573 $resaction .= $langs->trans(
"NbSelected").
': '.count($toselect).
"\n<br>";
574 $resaction .= $langs->trans(
"NbIgnored").
': '.($nbignored ? $nbignored : 0).
"\n<br>";
575 $resaction .= $langs->trans(
"NbSent").
': '.($nbsent ? $nbsent : 0).
"\n<br>";
581 setEventMessages($langs->trans(
"EMailSentForNElements", $nbsent.
'/'.count($toselect)), null,
'mesgs');
593 if ($massaction ==
'confirm_createbills')
595 $orders =
GETPOST(
'toselect',
'array');
596 $createbills_onebythird =
GETPOST(
'createbills_onebythird',
'int');
597 $validate_invoices =
GETPOST(
'validate_invoices',
'int');
600 $TFactThird = array();
602 $nb_bills_created = 0;
606 foreach ($orders as $id_order)
609 if ($cmd->fetch($id_order) <= 0)
continue;
612 if (!empty($createbills_onebythird) && !empty($TFactThird[$cmd->socid])) $objecttmp = $TFactThird[$cmd->socid];
615 $cmd->fetch_optionals();
617 $objecttmp->socid = $cmd->socid;
618 $objecttmp->type = $objecttmp::TYPE_STANDARD;
619 $objecttmp->cond_reglement_id = $cmd->cond_reglement_id;
620 $objecttmp->mode_reglement_id = $cmd->mode_reglement_id;
621 $objecttmp->fk_project = $cmd->fk_project;
622 $objecttmp->multicurrency_code = $cmd->multicurrency_code;
623 if (empty($createbills_onebythird)) $objecttmp->ref_client = $cmd->ref_client;
626 if (empty($datefacture))
631 $objecttmp->date = $datefacture;
632 $objecttmp->origin =
'commande';
633 $objecttmp->origin_id = $id_order;
635 $objecttmp->array_options = $cmd->array_options;
637 $res = $objecttmp->create($user);
639 if ($res > 0) $nb_bills_created++;
642 if ($objecttmp->id > 0)
644 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"element_element (";
646 $sql .=
", sourcetype";
647 $sql .=
", fk_target";
648 $sql .=
", targettype";
649 $sql .=
") VALUES (";
651 $sql .=
", '".$db->escape($objecttmp->origin).
"'";
652 $sql .=
", ".$objecttmp->id;
653 $sql .=
", '".$db->escape($objecttmp->element).
"'";
656 if (!$db->query($sql))
663 $lines = $cmd->lines;
664 if (empty($lines) && method_exists($cmd,
'fetch_lines'))
667 $lines = $cmd->lines;
671 $num = count($lines);
673 for ($i = 0; $i < $num; $i++)
675 $desc = ($lines[$i]->desc ? $lines[$i]->desc :
'');
677 if (!empty($createbills_onebythird))
682 if ($lines[$i]->subprice < 0)
686 $discount->fk_soc = $objecttmp->socid;
687 $discount->amount_ht = abs($lines[$i]->total_ht);
688 $discount->amount_tva = abs($lines[$i]->total_tva);
689 $discount->amount_ttc = abs($lines[$i]->total_ttc);
690 $discount->tva_tx = $lines[$i]->tva_tx;
691 $discount->fk_user = $user->id;
692 $discount->description = $desc;
693 $discountid = $discount->create($user);
696 $result = $objecttmp->insert_discount($discountid);
705 $product_type = ($lines[$i]->product_type ? $lines[$i]->product_type : 0);
708 if ($lines[$i]->date_debut_prevue) $date_start = $lines[$i]->date_debut_prevue;
709 if ($lines[$i]->date_debut_reel) $date_start = $lines[$i]->date_debut_reel;
710 if ($lines[$i]->date_start) $date_start = $lines[$i]->date_start;
713 if ($lines[$i]->date_fin_prevue) $date_end = $lines[$i]->date_fin_prevue;
714 if ($lines[$i]->date_fin_reel) $date_end = $lines[$i]->date_fin_reel;
715 if ($lines[$i]->date_end) $date_end = $lines[$i]->date_end;
717 if (($lines[$i]->product_type != 9 && empty($lines[$i]->fk_parent_line)) || $lines[$i]->product_type == 9)
723 if (method_exists($lines[$i],
'fetch_optionals')) {
724 $lines[$i]->fetch_optionals();
725 $array_options = $lines[$i]->array_options;
728 $result = $objecttmp->addline(
730 $lines[$i]->subprice,
733 $lines[$i]->localtax1_tx,
734 $lines[$i]->localtax2_tx,
735 $lines[$i]->fk_product,
736 $lines[$i]->remise_percent,
740 $lines[$i]->info_bits,
741 $lines[$i]->fk_remise_except,
746 $lines[$i]->special_code,
750 $lines[$i]->fk_fournprice,
767 if ($result > 0 && $lines[$i]->product_type == 9)
769 $fk_parent_line = $result;
778 if (!empty($createbills_onebythird) && empty($TFactThird[$cmd->socid])) $TFactThird[$cmd->socid] = $objecttmp;
779 else $TFact[$objecttmp->id] = $objecttmp;
783 $TAllFact = empty($createbills_onebythird) ? $TFact : $TFactThird;
786 if (!$error && $validate_invoices)
788 $massaction = $action =
'builddoc';
790 foreach ($TAllFact as &$objecttmp)
792 $result = $objecttmp->validate($user);
800 $id = $objecttmp->id;
801 $object = $objecttmp;
805 $upload_dir = $conf->facture->dir_output;
806 $permissiontoadd = $user->rights->facture->creer;
809 $savobject = $object;
810 $object = $objecttmp;
811 include DOL_DOCUMENT_ROOT.
'/core/actions_builddoc.inc.php';
812 $object = $savobject;
815 $massaction = $action =
'confirm_createbills';
821 setEventMessages($langs->trans(
'BillCreated', $nb_bills_created), null,
'mesgs');
825 if (!empty($contextpage) && $contextpage !=
$_SERVER[
"PHP_SELF"]) $param .=
'&contextpage='.urlencode($contextpage);
826 if ($limit > 0 && $limit != $conf->liste_limit) $param .=
'&limit='.urlencode($limit);
827 if ($sall) $param .=
'&sall='.urlencode($sall);
828 if ($socid > 0) $param .=
'&socid='.urlencode($socid);
829 if ($search_status !=
'') $param .=
'&search_status='.urlencode($search_status);
830 if ($search_orderday) $param .=
'&search_orderday='.urlencode($search_orderday);
831 if ($search_ordermonth) $param .=
'&search_ordermonth='.urlencode($search_ordermonth);
832 if ($search_orderyear) $param .=
'&search_orderyear='.urlencode($search_orderyear);
833 if ($search_deliveryday) $param .=
'&search_deliveryday='.urlencode($search_deliveryday);
834 if ($search_deliverymonth) $param .=
'&search_deliverymonth='.urlencode($search_deliverymonth);
835 if ($search_deliveryyear) $param .=
'&search_deliveryyear='.urlencode($search_deliveryyear);
836 if ($search_ref) $param .=
'&search_ref='.urlencode($search_ref);
837 if ($search_company) $param .=
'&search_company='.urlencode($search_company);
838 if ($search_ref_customer) $param .=
'&search_ref_customer='.urlencode($search_ref_customer);
839 if ($search_user > 0) $param .=
'&search_user='.urlencode($search_user);
840 if ($search_sale > 0) $param .=
'&search_sale='.urlencode($search_sale);
841 if ($search_total_ht !=
'') $param .=
'&search_total_ht='.urlencode($search_total_ht);
842 if ($search_total_vat !=
'') $param .=
'&search_total_vat='.urlencode($search_total_vat);
843 if ($search_total_ttc !=
'') $param .=
'&search_total_ttc='.urlencode($search_total_ttc);
844 if ($search_project_ref >= 0) $param .=
"&search_project_ref=".urlencode($search_project_ref);
845 if ($show_files) $param .=
'&show_files='.urlencode($show_files);
846 if ($optioncss !=
'') $param .=
'&optioncss='.urlencode($optioncss);
847 if ($billed !=
'') $param .=
'&billed='.urlencode($billed);
849 header(
"Location: ".
$_SERVER[
'PHP_SELF'].
'?'.$param);
854 $_GET[
"origin"] = $_POST[
"origin"];
855 $_GET[
"originid"] = $_POST[
"originid"];
861 if (!$error && $massaction ==
'cancelorders')
868 $orders =
GETPOST(
'toselect',
'array');
869 foreach ($orders as $id_order)
872 if ($cmd->fetch($id_order) <= 0)
877 $langs->load(
'errors');
878 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusValidToBeCanceled", $cmd->ref), null,
'errors');
883 $result = $cmd->cancel();
897 else setEventMessages($langs->trans(
"RecordsModified", $nbok), null,
'mesgs');
905 if (!$error && $massaction ==
"builddoc" && $permissiontoread && !
GETPOST(
'button_search'))
907 if (empty($diroutputmassaction))
909 dol_print_error(null,
'include of actions_massactions.inc.php is done but var $diroutputmassaction was not defined');
913 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
914 require_once DOL_DOCUMENT_ROOT.
'/core/lib/pdf.lib.php';
915 require_once DOL_DOCUMENT_ROOT.
'/core/lib/date.lib.php';
917 $objecttmp =
new $objectclass($db);
918 $listofobjectid = array();
919 $listofobjectthirdparties = array();
920 $listofobjectref = array();
921 foreach ($toselect as $toselectid)
923 $objecttmp =
new $objectclass($db);
924 $result = $objecttmp->fetch($toselectid);
927 $listofobjectid[$toselectid] = $toselectid;
928 $thirdpartyid = $objecttmp->fk_soc ? $objecttmp->fk_soc : $objecttmp->socid;
929 $listofobjectthirdparties[$thirdpartyid] = $thirdpartyid;
930 $listofobjectref[$toselectid] = $objecttmp->ref;
934 $arrayofinclusion = array();
935 foreach ($listofobjectref as $tmppdf) $arrayofinclusion[] =
'^'.preg_quote(
dol_sanitizeFileName($tmppdf),
'/').
'\.pdf$';
936 foreach ($listofobjectref as $tmppdf) $arrayofinclusion[] =
'^'.preg_quote(
dol_sanitizeFileName($tmppdf),
'/').
'_[a-zA-Z0-9-_]+\.pdf$';
937 $listoffiles =
dol_dir_list($uploaddir,
'all', 1, implode(
'|', $arrayofinclusion),
'\.meta$|\.png',
'date', SORT_DESC, 0,
true);
941 foreach ($listofobjectref as $basename)
944 foreach ($listoffiles as $filefound)
946 if (strstr($filefound[
"name"], $basename))
948 $files[] = $uploaddir.
'/'.$basename.
'/'.$filefound[
"name"];
955 $outputlangs = $langs;
957 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
958 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) $newlang = $objecttmp->thirdparty->default_lang;
959 if (!empty($newlang)) {
961 $outputlangs->setDefaultLang($newlang);
964 if (!empty($conf->global->USE_PDFTK_FOR_PDF_CONCAT))
971 $filename = preg_replace(
'/\s/',
'_', $filename);
974 if (in_array($objecttmp->element, array(
'facture',
'facture_fournisseur')) && $search_status ==
Facture::STATUS_VALIDATED)
979 if ($year) $filename .=
'_'.$year;
980 if ($month) $filename .=
'_'.$month;
982 if (count($files) > 0)
985 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
988 foreach ($files as $f) {
989 $input_files .=
' '.escapeshellarg($f);
992 $cmd =
'pdftk '.$input_files.
' cat output '.escapeshellarg($file);
996 if (file_exists($file)) {
997 if (!empty($conf->global->MAIN_UMASK))
998 @chmod($file, octdec($conf->global->MAIN_UMASK));
1000 $langs->load(
"exports");
1003 setEventMessages($langs->trans(
'ErrorPDFTkOutputFileNotFound'), null,
'errors');
1006 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'), null,
'errors');
1011 $page_largeur = $formatarray[
'width'];
1012 $page_hauteur = $formatarray[
'height'];
1013 $format = array($page_largeur, $page_hauteur);
1017 if (class_exists(
'TCPDF'))
1019 $pdf->setPrintHeader(
false);
1020 $pdf->setPrintFooter(
false);
1024 if (!empty($conf->global->MAIN_DISABLE_PDF_COMPRESSION)) $pdf->SetCompression(
false);
1027 foreach ($files as $file)
1030 $pagecount = $pdf->setSourceFile($file);
1031 for ($i = 1; $i <= $pagecount; $i++)
1033 $tplidx = $pdf->importPage($i);
1034 $s = $pdf->getTemplatesize($tplidx);
1035 $pdf->AddPage($s[
'h'] > $s[
'w'] ?
'P' :
'L');
1036 $pdf->useTemplate($tplidx);
1045 $filename = preg_replace(
'/\s/',
'_', $filename);
1048 if (in_array($objecttmp->element, array(
'facture',
'facture_fournisseur')) && $search_status ==
Facture::STATUS_VALIDATED)
1053 if ($year) $filename .=
'_'.$year;
1054 if ($month) $filename .=
'_'.$month;
1058 $file = $diroutputmassaction.
'/'.$filename.
'_'.
dol_print_date($now,
'dayhourlog').
'.pdf';
1059 $pdf->Output($file,
'F');
1060 if (!empty($conf->global->MAIN_UMASK))
1061 @chmod($file, octdec($conf->global->MAIN_UMASK));
1063 $langs->load(
"exports");
1066 setEventMessages($langs->trans(
'NoPDFAvailableForDocGenAmongChecked'), null,
'errors');
1072 if ($action ==
'remove_file')
1074 require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
1076 $langs->load(
"other");
1077 $upload_dir = $diroutputmassaction;
1078 $file = $upload_dir.
'/'.
GETPOST(
'file');
1087 if (!$error && $massaction ==
'validate' && $permissiontoadd)
1089 $objecttmp =
new $objectclass($db);
1091 if (($objecttmp->element ==
'facture' || $objecttmp->element ==
'invoice') && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_BILL))
1093 $langs->load(
"errors");
1094 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null,
'errors');
1097 if ($objecttmp->element ==
'invoice_supplier' && !empty($conf->stock->enabled) && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL))
1099 $langs->load(
"errors");
1100 setEventMessages($langs->trans(
'ErrorMassValidationNotAllowedWhenStockIncreaseOnAction'), null,
'errors');
1108 foreach ($toselect as $toselectid)
1110 $result = $objecttmp->fetch($toselectid);
1113 $result = $objecttmp->validate($user);
1115 $langs->load(
"errors");
1116 setEventMessages($langs->trans(
"ErrorObjectMustHaveStatusDraftToBeValidated", $objecttmp->ref), null,
'errors');
1119 } elseif ($result < 0) {
1126 if (empty($conf->global->MAIN_DISABLE_PDF_AUTOUPDATE)) {
1127 $outputlangs = $langs;
1129 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) {
1130 $newlang =
GETPOST(
'lang_id',
'aZ09');
1132 if ($conf->global->MAIN_MULTILANGS && empty($newlang)) {
1133 $newlang = $objecttmp->thirdparty->default_lang;
1135 if (!empty($newlang)) {
1136 $outputlangs =
new Translate(
"", $conf);
1137 $outputlangs->setDefaultLang($newlang);
1138 $outputlangs->load(
'products');
1140 $model = $objecttmp->model_pdf;
1141 $ret = $objecttmp->fetch($objecttmp->id);
1143 $hidedetails = !empty($hidedetails) ? $hidedetails : 0;
1144 $hidedesc = !empty($hidedesc) ? $hidedesc : 0;
1145 $hideref = !empty($hideref) ? $hideref : 0;
1146 $moreparams = !empty($moreparams) ? $moreparams : null;
1148 $result = $objecttmp->generateDocument($model, $outputlangs, $hidedetails, $hidedesc, $hideref);
1164 if ($nbok > 1)
setEventMessages($langs->trans(
"RecordsModified", $nbok), null,
'mesgs');
1165 else setEventMessages($langs->trans(
"RecordsModified", $nbok), null,
'mesgs');
1175 if (!$error && $massaction ==
'closed' && $objectclass ==
"Propal" && $permissiontoclose) {
1178 $objecttmp =
new $objectclass($db);
1180 foreach ($toselect as $toselectid) {
1181 $result = $objecttmp->fetch($toselectid);
1183 $result = $objecttmp->cloture($user, 3);
1199 else setEventMessages($langs->trans(
"RecordsModified", $nbok), null,
'mesgs');
1209 if (!$error && ($massaction ==
'delete' || ($action ==
'delete' && $confirm ==
'yes')) && $permissiontodelete)
1213 $objecttmp =
new $objectclass($db);
1215 foreach ($toselect as $toselectid)
1217 $result = $objecttmp->fetch($toselectid);
1221 if ($objectclass ==
'Facture' && empty($conf->global->INVOICE_CAN_ALWAYS_BE_REMOVED) && $objecttmp->status !=
Facture::STATUS_DRAFT)
1223 $langs->load(
"errors");
1225 $resaction .=
'<div class="error">'.$langs->trans(
'ErrorOnlyDraftStatusCanBeDeletedInMassAction', $objecttmp->ref).
'</div><br>';
1229 if ($objectclass ==
"Task" && $objecttmp->hasChildren() > 0)
1231 $sql =
"UPDATE ".MAIN_DB_PREFIX.
"projet_task SET fk_task_parent = 0 WHERE fk_task_parent = ".$objecttmp->id;
1232 $res = $db->query($sql);
1241 if (in_array($objecttmp->element, array(
'societe',
'member'))) $result = $objecttmp->delete($objecttmp->id, $user, 1);
1242 else $result = $objecttmp->delete($user);
1259 if ($nbok > 1)
setEventMessages($langs->trans(
"RecordsDeleted", $nbok), null,
'mesgs');
1260 else setEventMessages($langs->trans(
"RecordDeleted", $nbok), null,
'mesgs');
1270 if (!$error && $massaction ==
'generate_doc' && $permissiontoread)
1274 $objecttmp =
new $objectclass($db);
1276 foreach ($toselect as $toselectid)
1278 $result = $objecttmp->fetch($toselectid);
1281 $outputlangs = $langs;
1284 if ($conf->global->MAIN_MULTILANGS && empty($newlang) &&
GETPOST(
'lang_id',
'aZ09')) $newlang =
GETPOST(
'lang_id',
'aZ09');
1285 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->thirdparty->default_lang)) $newlang = $objecttmp->thirdparty->default_lang;
1286 if ($conf->global->MAIN_MULTILANGS && empty($newlang) && isset($objecttmp->default_lang)) $newlang = $objecttmp->default_lang;
1287 if (!empty($newlang))
1289 $outputlangs =
new Translate(
"", $conf);
1290 $outputlangs->setDefaultLang($newlang);
1294 if (empty($hidedetails)) $hidedetails = 0;
1295 if (empty($hidedesc)) $hidedesc = 0;
1296 if (empty($hideref)) $hideref = 0;
1297 if (empty($moreparams)) $moreparams = null;
1299 $result = $objecttmp->generateDocument($objecttmp->modelpdf, $outputlangs, $hidedetails, $hidedesc, $hideref, $moreparams);
1316 if ($nbok > 1)
setEventMessages($langs->trans(
"RecordsGenerated", $nbok), null,
'mesgs');
1317 else setEventMessages($langs->trans(
"RecordGenerated", $nbok), null,
'mesgs');
1324 $parameters[
'toselect'] = $toselect;
1325 $parameters[
'uploaddir'] = $uploaddir;
1326 $parameters[
'massaction'] = $massaction;
1327 $parameters[
'diroutputmassaction'] = $diroutputmassaction;
1329 $reshook = $hookmanager->executeHooks(
'doMassActions', $parameters, $object, $action);
1330 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
pdf_getFormat(Translate $outputlangs=null, $mode= 'setup')
Return array with format properties of default PDF format.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm= 'auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_now($mode= 'auto')
Return date for now.
Class to manage Dolibarr users.
setEventMessage($mesgs, $style= 'mesgs')
Set event message in dol_events session object.
pdf_getPDFFont($outputlangs)
Return font name to use for PDF generation.
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...
getCommonSubstitutionArray($outputlangs, $onlykey=0, $exclude=null, $object=null)
Return array of possible common substitutions.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
Class to manage third parties objects (customers, suppliers, prospects...)
const STATUS_VALIDATED
Validated (need to be paid)
dol_mimetype($file, $default= 'application/octet-stream', $mode=0)
Return mime type of a file.
Class to send emails (with attachments or not) Usage: $mailfile = new CMailFile($subject,$sendto,$replyto,$message,$filepath,$mimetype,$filename,$cc,$ccc,$deliveryreceipt,$msgishtml,$errors_to,$css,$trackid,$moreinheader,$sendcontext,$replyto); $mailfile->sendfile();.
Class to manage customers orders.
const STATUS_DRAFT
Draft status.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
const STATUS_DRAFT
Draft status.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart= '')
Return a path to have a the directory according to object where files are stored. ...
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
Class to manage translations.
dol_sanitizeFileName($str, $newstr= '_', $unaccent=1)
Clean a string to use it as a file name.
dol_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter=null, $sortcriteria="name", $sortorder=SORT_ASC, $mode=0, $nohook=0, $relativename="", $donotfollowsymlinks=0)
Scan a directory and return a list of files/directories.
dol_is_file($pathoffile)
Return if path is a file.
print $_SERVER["PHP_SELF"]
Edit parameters.
const STATUS_DRAFT
Draft status.
const STATUS_VALIDATED
Validated status.
pdf_getInstance($format= '', $metric= 'mm', $pagetype= 'P')
Return a PDF instance object.
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_most_recent_file($dir, $regexfilter= '', $excludefilter=array('(\.meta|_preview.*\.png)$', '^\.'), $nohook=false, $mode= '')
Return file(s) into a directory (by default most recent)
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->don->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if((!empty($conf->fournisseur->enabled)&&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD)||!empty($conf->supplier_invoice->enabled))&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
Class to manage absolute discounts.
make_substitutions($text, $substitutionarray, $outputlangs=null)
Make substitution into a text string, replacing keys with vals from $substitutionarray (oldval=>newva...
Class to manage invoices.
dol_mkdir($dir, $dataroot= '', $newmask=null)
Creation of a directory (this can create recursive subdir)
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...