28require_once
'../main.inc.php';
37require_once DOL_DOCUMENT_ROOT.
'/core/class/html.form.class.php';
38require_once DOL_DOCUMENT_ROOT.
'/core/lib/files.lib.php';
39require_once DOL_DOCUMENT_ROOT.
'/ai/class/ai.class.php';
40require_once DOL_DOCUMENT_ROOT.
'/societe/class/societe.class.php';
41require_once DOL_DOCUMENT_ROOT.
'/product/class/product.class.php';
42require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
43require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.product.class.php';
44require_once DOL_DOCUMENT_ROOT.
'/salaries/class/salary.class.php';
45require_once DOL_DOCUMENT_ROOT.
'/compta/sociales/class/chargesociales.class.php';
46require_once DOL_DOCUMENT_ROOT.
'/expensereport/class/expensereport.class.php';
47require_once DOL_DOCUMENT_ROOT.
'/core/lib/price.lib.php';
49$langs->loadLangs(array(
"main",
"exports",
"other"));
51$action =
GETPOST(
'action',
'aZ09');
52$modulepart =
GETPOST(
'modulepart',
'aZ09');
57if (preg_match(
'/^idprod_(\d+)$/',
GETPOST(
'prodid',
'alpha'), $reg)) {
58 $prodid = (int) $reg[1];
61 if ($tmpproductfournisseur->fetch_product_fournisseur_price(
GETPOSTINT(
'prodid')) > 0) {
62 $prodid = (int) $tmpproductfournisseur->fk_product;
67if (preg_match(
'/^\d+$/',
GETPOST(
'feetypeid',
'aZ09'))) {
69} elseif (
GETPOST(
'feetypeid',
'aZ09') &&
GETPOST(
'feetypeid',
'aZ09') !=
'-1') {
70 $sql =
"SELECT id FROM ".$db->prefix().
"c_type_fees WHERE code = '".$db->escape(
GETPOST(
'feetypeid',
'aZ09')).
"'";
71 $resql = $db->query($sql);
72 if ($resql && ($obj = $db->fetch_object($resql))) {
73 $feetypeid = (int) $obj->id;
79$upload_dir =
$conf->user->dir_temp.
'/import';
84$originalfilename = $file;
85$uid = $thiid = $pid = $erid = $salid = 0;
87if (preg_match(
'/-uid([\d+])/', $file, $reg)) {
89 $originalfilename = preg_replace(
'/-uid\d+/',
'', $originalfilename);
91if (preg_match(
'/-thiid([\d+])/', $file, $reg)) {
93 $originalfilename = preg_replace(
'/-thiid\d+/',
'', $originalfilename);
95if (preg_match(
'/-pid([\d+])/', $file, $reg)) {
97 $originalfilename = preg_replace(
'/-pid\d+/',
'', $originalfilename);
99if (preg_match(
'/-erid([\d+])/', $file, $reg)) {
101 $originalfilename = preg_replace(
'/-erid\d+/',
'', $originalfilename);
103if (preg_match(
'/-salid([\d+])/', $file, $reg)) {
105 $originalfilename = preg_replace(
'/-salid\d+/',
'', $originalfilename);
107$originalfilename = preg_replace(
'/^upload_page-[a-z_]+-/',
'', $originalfilename);
114$uploadedfilename =
'';
119$converternamefortext =
'';
120$modelforanalysis =
'';
122$apiservice = $ai->getApiService();
124 $defaultmodel = ($apiservice !=
'custom' && !empty($arrayofaiservices[$apiservice][
'docparsing'][
'default']) && $arrayofaiservices[$apiservice][
'docparsing'][
'default'] !=
'na') ? $arrayofaiservices[$apiservice][
'docparsing'][
'default'] :
'';
125 $converternamefortext =
getDolGlobalString(
'AI_API_'.strtoupper($apiservice).
'_MODEL_DOCPARSING', $defaultmodel);
126} elseif (preg_match(
'/\.pdf$/i', $originalfilename)) {
127 $converternamefortext =
'pdftotext';
128} elseif (preg_match(
'/\.(png|jpe?g|gif|bmp|tiff?|webp)$/i', $originalfilename)) {
129 $converternamefortext =
'docling';
131$defaultmodelfortext = ($apiservice !=
'custom' && !empty($arrayofaiservices[$apiservice][
'textgeneration'][
'default'])) ? $arrayofaiservices[$apiservice][
'textgeneration'][
'default'] :
'';
132$modelforanalysis =
getDolGlobalString(
'AI_API_'.strtoupper($apiservice).
'_MODEL_TEXT', $defaultmodelfortext);
134if (empty($converternamefortext)) {
135 $converternamefortext = $langs->trans(
"AIModelNotConfigured");
137if (empty($modelforanalysis)) {
138 $modelforanalysis = $langs->trans(
"AIModelNotConfigured");
149 header(
"Location: ".$urlforuploadpage);
159if ($action ==
'displayfile') {
162 if (!preg_match(
'/^upload_page-[a-z_]+-uid'.((
int) $user->id).
'-/', $filetodisplay)
163 || !preg_match(
'/^(application\/pdf|image\/(png|jpeg|gif|webp|bmp))$/', $mimetodisplay)
169 header(
'Content-Disposition: inline; filename="'.
dol_escape_htmltag($filetodisplay).
'"');
170 header(
'Content-Length: '.
dol_filesize($upload_dir.
'/'.$filetodisplay));
177if ($action ==
'uploadfile') {
179 print
'Error, modulepart param is empty';
186 $module = $arrayobject[
'module'];
187 $element = $arrayobject[
'element'];
188 $dir_output = $arrayobject[
'dir_output'];
189 $dir_temp = $arrayobject[
'dir_temp'];
191 $permlevel1 =
'read';
193 $fileprefix =
'unknown';
194 if (in_array($modulepart, array(
'fournisseur',
'invoice_supplier'))) {
195 $permlevel1 =
'facture';
196 $permlevel2 =
'read';
198 } elseif ($modulepart ==
'expensereport') {
199 $permlevel1 =
'lire';
200 $fileprefix =
'upload_page-'.$modulepart.
'-uid'.$user->id.
'-erid'.(
GETPOSTINT(
'userexpensereportid') > 0 ?
GETPOSTINT(
'userexpensereportid') : 0).
'-pid'.(
GETPOSTINT(
'search_prodid') > 0 ?
GETPOSTINT(
'search_prodid') : 0);
201 } elseif ($modulepart ==
'salaries') {
202 $fileprefix =
'upload_page-'.$modulepart.
'-uid'.$user->id.
'-salid'.(
GETPOSTINT(
'usersalaryid') > 0 ?
GETPOSTINT(
'usersalaryid') : 0);
203 } elseif ($modulepart ==
'chargesociales') {
204 $permlevel1 =
'charges';
205 $permlevel2 =
'lire';
206 $fileprefix =
'upload_page-'.$modulepart.
'-uid'.$user->id;
210 $permissiontoadd = $user->hasRight(
$module, $permlevel1, $permlevel2);
212 $permissiontoadd = $user->hasRight(
$module, $permlevel1);
214 $forceFullTextIndexation =
'0';
217 if (!empty($_FILES[
'userfile'][
'name'])) {
218 $uploadedfilename = $_FILES[
'userfile'][
'name'];
219 $fullnewname = $fileprefix.
'-'.$_FILES[
'userfile'][
'name'];
220 $_FILES[
'userfile'][
'name'] = $fullnewname;
228 include DOL_DOCUMENT_ROOT.
'/core/actions_linkedfiles.inc.php';
236 unset($_SESSION[
'dol_events'][
'mesgs']);
239 $ajaxFileUrl = DOL_URL_ROOT.
'/core/ajax/ajaxuploadpage.php?file='.urlencode($fullnewname);
247if ($action ==
'addobject') {
248 $mandatoryfieldsareko = 0;
250 if ($modulepart ==
'invoice_supplier' &&
GETPOSTINT(
'invoiceid') <= 0) {
253 $langs->load(
"companies");
254 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"ThirdParty")),
null,
'errors');
255 $mandatoryfieldsareko = 1;
258 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Product")),
null,
'errors');
259 $mandatoryfieldsareko = 1;
262 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Amount")),
null,
'errors');
263 $mandatoryfieldsareko = 1;
265 if (!
GETPOST(
'supplierref',
'alphanohtml')) {
266 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"RefSupplier")),
null,
'errors');
267 $mandatoryfieldsareko = 1;
271 $sql =
"SELECT rowid FROM ".$db->prefix().
"facture_fourn";
272 $sql .=
" WHERE ref_supplier = '".$db->escape(trim(
GETPOST(
'supplierref',
'alphanohtml'))).
"'";
273 $sql .=
" AND fk_soc = ".((int)
GETPOSTINT(
'socid'));
274 $sql .=
" AND entity IN (".getEntity(
'facture_fourn').
")";
275 $sql .= $db->plimit(1);
276 $resql = $db->query($sql);
278 setEventMessages($db->lasterror(),
null,
'errors');
279 $mandatoryfieldsareko = 1;
280 } elseif ($db->num_rows($resql) > 0) {
281 $langs->load(
"errors");
282 setEventMessages($langs->trans(
"ErrorRefAlreadyExists",
GETPOST(
'supplierref',
'alphanohtml')),
null,
'errors');
283 $mandatoryfieldsareko = 1;
287 if ($modulepart ==
'invoice_supplier') {
288 if (!$user->hasRight(
'fournisseur',
'facture',
'creer') && !$user->hasRight(
'supplier_invoice',
'creer')) {
289 setEventMessages($langs->trans(
"NotEnoughPermissions"),
null,
'errors');
290 $mandatoryfieldsareko = 1;
292 } elseif ($modulepart ==
'salaries') {
294 $langs->load(
"salaries");
299 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Employee")),
null,
'errors');
300 $mandatoryfieldsareko = 1;
302 if (!
GETPOST(
'label',
'alphanohtml')) {
303 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
304 $mandatoryfieldsareko = 1;
306 if (empty($datesp) || empty($dateep)) {
307 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Period")),
null,
'errors');
308 $mandatoryfieldsareko = 1;
311 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Amount")),
null,
'errors');
312 $mandatoryfieldsareko = 1;
314 if (!$mandatoryfieldsareko) {
316 $sql =
"SELECT rowid FROM ".$db->prefix().
"salary";
317 $sql .=
" WHERE fk_user = ".((int)
GETPOSTINT(
'usersalaryid'));
318 $sql .=
" AND datesp = '".$db->escape(
dol_print_date($datesp,
'dayrfc')).
"'";
319 $sql .=
" AND dateep = '".$db->escape(
dol_print_date($dateep,
'dayrfc')).
"'";
320 $sql .=
" AND entity IN (".getEntity(
'salary').
")";
321 $sql .= $db->plimit(1);
322 $resql = $db->query($sql);
324 setEventMessages($db->lasterror(),
null,
'errors');
325 $mandatoryfieldsareko = 1;
326 } elseif ($db->num_rows($resql) > 0) {
327 $langs->load(
"errors");
328 setEventMessages($langs->trans(
"ErrorSalaryAlreadyExistsForThisPeriod"),
null,
'errors');
329 $mandatoryfieldsareko = 1;
332 if (!$user->hasRight(
'salaries',
'write')) {
333 setEventMessages($langs->trans(
"NotEnoughPermissions"),
null,
'errors');
334 $mandatoryfieldsareko = 1;
336 } elseif ($modulepart ==
'chargesociales') {
339 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
340 $mandatoryfieldsareko = 1;
342 if (!
GETPOST(
'label',
'alphanohtml')) {
343 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Label")),
null,
'errors');
344 $mandatoryfieldsareko = 1;
347 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"DateDue")),
null,
'errors');
348 $mandatoryfieldsareko = 1;
351 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"PeriodEndDate")),
null,
'errors');
352 $mandatoryfieldsareko = 1;
355 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Amount")),
null,
'errors');
356 $mandatoryfieldsareko = 1;
358 if (!$user->hasRight(
'tax',
'charges',
'creer')) {
359 setEventMessages($langs->trans(
"NotEnoughPermissions"),
null,
'errors');
360 $mandatoryfieldsareko = 1;
362 } elseif ($modulepart ==
'expensereport') {
364 $langs->loadLangs(array(
"trips",
"hrm"));
366 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Employee")),
null,
'errors');
367 $mandatoryfieldsareko = 1;
369 if ($feetypeid <= 0) {
370 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Type")),
null,
'errors');
371 $mandatoryfieldsareko = 1;
374 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Date")),
null,
'errors');
375 $mandatoryfieldsareko = 1;
378 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"AmountTTC")),
null,
'errors');
379 $mandatoryfieldsareko = 1;
382 setEventMessages($langs->trans(
"ErrorFieldRequired", $langs->transnoentitiesnoconv(
"Project")),
null,
'errors');
383 $mandatoryfieldsareko = 1;
386 if (!$user->hasRight(
'expensereport',
'creer') && !(
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') && $user->hasRight(
'expensereport',
'writeall_advance'))) {
387 setEventMessages($langs->trans(
"NotEnoughPermissions"),
null,
'errors');
388 $mandatoryfieldsareko = 1;
389 } elseif (
GETPOSTINT(
'userexpensereportid') > 0 && (!
getDolGlobalString(
'MAIN_USE_ADVANCED_PERMS') || !$user->hasRight(
'expensereport',
'writeall_advance'))) {
390 if (!in_array(
GETPOSTINT(
'userexpensereportid'), $user->getAllChildIds(1))) {
391 setEventMessages($langs->trans(
"UserNotInHierachy"),
null,
'errors');
392 $mandatoryfieldsareko = 1;
397 if ($mandatoryfieldsareko) {
398 $action =
'showsummary';
402$createdobject =
null;
406$attachtoexistinginvoice = 0;
407if ($action ==
'addobject' && in_array($modulepart, array(
'invoice_supplier',
'salaries',
'chargesociales',
'expensereport'))) {
412if ($action ==
'addobject' && $modulepart ==
'invoice_supplier' &&
GETPOSTINT(
'invoiceid') > 0) {
415 $result = $createdobject->fetch(
GETPOSTINT(
'invoiceid'));
416 if ($result <= 0 || !in_array($createdobject->entity, explode(
',',
getEntity(
'facture_fourn')))) {
418 $langs->load(
"errors");
419 setEventMessages($langs->trans(
"ErrorRecordNotFound"),
null,
'errors');
421 $attachtoexistinginvoice = 1;
422 $destdir =
getMultidirOutput($createdobject).
'/'.
get_exdir($createdobject->id, 2, 0, 0, $createdobject,
'invoice_supplier').dol_sanitizeFileName($createdobject->ref);
424} elseif ($action ==
'addobject' && $modulepart ==
'invoice_supplier') {
425 $tmpthirdparty =
new Societe($db);
427 $tmpproduct =
new Product($db);
428 $tmpproduct->fetch($prodid);
431 $vat_rate =
GETPOST(
'vat_rate',
'alphanohtml');
432 if ($vat_rate ===
'') {
436 $currency_code =
GETPOST(
'currency_code',
'aZ09');
439 $createdobject->socid = $tmpthirdparty->id;
441 $createdobject->ref_supplier =
GETPOST(
'supplierref',
'alphanohtml');
447 $dateinvoice =
dol_mktime(0, 0, 0, (
int) $reg[2], (
int) $reg[3], (
int) $reg[1],
'tzserver');
450 $datedue =
dol_mktime(0, 0, 0, (
int) $reg[2], (
int) $reg[3], (
int) $reg[1],
'tzserver');
452 $createdobject->date = $dateinvoice;
453 $createdobject->label =
GETPOST(
'invoice_label',
'alphanohtml');
454 $createdobject->libelle = $createdobject->label;
455 $createdobject->cond_reglement_id = $tmpthirdparty->cond_reglement_supplier_id;
456 $createdobject->mode_reglement_id = $tmpthirdparty->mode_reglement_supplier_id;
457 $createdobject->fk_account = $tmpthirdparty->fk_account;
459 if (
isModEnabled(
'multicurrency') && $currency_code && $currency_code !=
$conf->currency) {
460 $createdobject->multicurrency_code = $currency_code;
461 $pu_devise = $amount_ttc;
463 $createdobject->date_echeance = $datedue;
464 if (empty($createdobject->date_echeance)) {
465 $createdobject->date_echeance = $createdobject->calculate_date_lim_reglement();
468 $result = $createdobject->create($user);
471 setEventMessages($createdobject->error, $createdobject->errors,
'errors');
478 $result = $createdobject->addline(
'', $amount_ttc, $vat_rate, $localtax1, $localtax2, 1, $tmpproduct->id, 0, 0, 0, 0, 0,
'TTC', $tmpproduct->type, -1, 0, array(),
null, 0, $pu_devise);
481 setEventMessages($createdobject->error, $createdobject->errors,
'errors');
486 $destdir =
getMultidirOutput($createdobject).
'/'.
get_exdir($createdobject->id, 2, 0, 0, $createdobject,
'invoice_supplier').dol_sanitizeFileName($createdobject->ref);
489if ($action ==
'addobject' && $modulepart ==
'salaries') {
490 $fuser =
new User($db);
493 $createdobject =
new Salary($db);
494 $createdobject->fk_user = $fuser->id;
495 $createdobject->label =
GETPOST(
'label',
'alphanohtml');
499 $createdobject->salary = $fuser->salary;
500 $createdobject->type_payment = 0;
501 $createdobject->fk_user_author = $user->id;
503 $createdobject->note = $langs->transnoentitiesnoconv(
"GrossSalary").
': '.
price(
GETPOSTFLOAT(
'gross_salary'), 0, $langs, 1, -1, -1,
$conf->currency);
506 $result = $createdobject->create($user);
509 setEventMessages($createdobject->error, $createdobject->errors,
'errors');
511 $createdobject->fetch($createdobject->id);
515if ($action ==
'addobject' && $modulepart ==
'chargesociales') {
517 $createdobject->type =
GETPOSTINT(
'socialcontrib');
518 $createdobject->label =
GETPOST(
'label',
'alphanohtml');
523 $createdobject->paye = ChargeSociales::STATUS_UNPAID;
525 $result = $createdobject->create($user);
528 setEventMessages($createdobject->error, $createdobject->errors,
'errors');
530 $createdobject->fetch($createdobject->id);
534if ($action ==
'addobject' && $modulepart ==
'expensereport') {
536 $fuser =
new User($db);
537 $fuser->fetch(
GETPOSTINT(
'userexpensereportid'));
541 $sql =
"SELECT rowid FROM ".$db->prefix().
"expensereport";
542 $sql .=
" WHERE fk_user_author = ".((int) $fuser->id);
544 $sql .=
" AND date_debut <= '".$db->escape(
dol_print_date($dateexpense,
'dayrfc')).
"' AND date_fin >= '".$db->escape(
dol_print_date($dateexpense,
'dayrfc')).
"'";
545 $sql .=
" AND entity IN (".getEntity(
'expensereport').
")";
546 $sql .=
" ORDER BY rowid DESC";
547 $sql .= $db->plimit(1);
548 $resql = $db->query($sql);
549 $obj = ($resql ? $db->fetch_object($resql) :
null);
552 setEventMessages($db->lasterror(),
null,
'errors');
554 $createdobject->fetch($obj->rowid);
558 $createdobject->date_debut =
dol_get_first_day($tmpdate[
'year'], $tmpdate[
'mon']);
559 $createdobject->date_fin =
dol_get_last_day($tmpdate[
'year'], $tmpdate[
'mon']);
560 $createdobject->fk_user_author = $fuser->id;
561 $createdobject->fk_user_validator = $fuser->fk_user_expense_validator;
564 if (!
getDolGlobalString(
'EXPENSEREPORT_ALLOW_OVERLAPPING_PERIODS') && $createdobject->periodExists($fuser, $createdobject->date_debut, $createdobject->date_fin) > 0) {
566 setEventMessages($langs->trans(
"ErrorDoubleDeclaration"),
null,
'errors');
568 $result = $createdobject->create($user);
571 setEventMessages($createdobject->error, $createdobject->errors,
'errors');
573 $createdobject->fetch($result);
581if ($action ==
'addobject' && in_array($modulepart, array(
'invoice_supplier',
'salaries',
'chargesociales',
'expensereport'))) {
583 if (!$error && $destdir) {
585 if (preg_match(
'/^upload_page-[a-z_]+-uid'.((
int) $user->id).
'-/', $filetoattach) &&
dol_is_file($upload_dir.
'/'.$filetoattach)) {
586 $destfilename = preg_replace(
'/^upload_page-[a-z_]+-uid\d+(-(thiid|pid|erid|salid)\d+)*-/',
'', $filetoattach);
588 $result =
dol_move($upload_dir.
'/'.$filetoattach, $destdir.
'/'.$destfilename,
'0', 1, 0, 1, array(
'gen_or_uploaded' =>
'uploaded'));
591 $langs->load(
"errors");
592 setEventMessages($langs->trans(
"ErrorFailToRenameFile", $filetoattach, $destfilename),
null,
'errors');
602 if (!empty($destfilename)) {
603 include_once DOL_DOCUMENT_ROOT.
'/ecm/class/ecmfiles.class.php';
605 $ecmfiles->fetch(0,
'',
'expensereport/'.
dol_sanitizeFileName($createdobject->ref).
'/'.$destfilename);
606 $fk_ecm_files = (int) $ecmfiles->id;
609 $result = $createdobject->addline(1, (
float)
price2num(
GETPOST(
'amount_ttc',
'alpha'),
'MU'), $feetypeid, $vatrate, $dateexpense,
GETPOST(
'comments',
'alphanohtml'), 0, 0, 0, $fk_ecm_files);
612 setEventMessages($createdobject->error, $createdobject->errors,
'errors');
621 $urltocreatedobject =
'/fourn/facture/card.php?id='.$createdobject->id;
622 if ($createdobject instanceof
Salary) {
623 $urltocreatedobject =
'/salaries/card.php?id='.$createdobject->id;
624 setEventMessages($langs->trans(
"SalaryCreatedFromFile"),
null,
'mesgs');
626 $urltocreatedobject =
'/compta/sociales/card.php?id='.$createdobject->id;
627 setEventMessages($langs->trans(
"SocialContributionCreatedFromFile"),
null,
'mesgs');
629 $urltocreatedobject =
'/expensereport/card.php?id='.$createdobject->id;
630 setEventMessages($langs->trans(
"ExpenseAddedFromFile"),
null,
'mesgs');
631 } elseif ($attachtoexistinginvoice) {
632 setEventMessages($langs->trans(
"FileAttachedToExistingInvoice"),
null,
'mesgs');
634 setEventMessages($langs->trans(
"DraftInvoiceCreatedFromFile"),
null,
'mesgs');
641 $createdobject =
null;
642 $action =
'showsummary';
651$form =
new Form($db);
667$title = $langs->trans(
"UploadFile");
671$arrayofcss = array();
673llxHeader(
'', $title, $help_url,
'', 0, 0, $arrayofjs, $arrayofcss,
'',
'mod-upload page-card');
675print
load_fiche_titre(
'',
'',
'', 0,
'',
'',
'<h2>'.img_picto(
'',
'upload').
' '.$title.
'</h2>');
679$hookmanager->initHooks(array(
'uploadform'));
687 $uploadform =
'<div class="display-flex">';
690 $prodtext = $langs->trans(
"RefOrLabel");
692 $langs->load(
"bills");
694 <div id="supplierinvoice" class="flex-item flex-item-uploadfile">'.img_picto(
'',
'bill',
'class="fa-2x"').
'<br>
695 <div>'.$langs->trans(
"SupplierInvoice").
'<br><br>';
701 $uploadform .= img_picto(
'',
'company',
'class="pictofixedwidth"');
702 $uploadform .= $form->select_company($socid,
'socid',
'(statut:=:0)', $langs->transnoentitiesnoconv(
"Supplier"), 0, 0, array(), 0,
'maxwidth200 disableautoopen');
704 $uploadform .=
'<br>';
707 $uploadform .= img_picto(
'',
'product',
'class="pictofixedwidth"');
708 $uploadform .= $form->select_produits_fournisseurs(0, $prodid,
'prodid',
'',
'', array(), 1, 1,
'maxwidth200 disableautoopen', $prodtext, 1);
710 $uploadform .=
'<br>';
713 <small class="opacitymedium">'.$langs->trans(
"OrClickToSelectAFile").
'...</small>
720 $langs->load(
"expensereport");
722 <div id="userexpensereport" class="flex-item flex-item-uploadfile">'.img_picto(
'',
'expensereport',
'class="fa-2x"').
'<br>
723 <div>'.$langs->trans(
"ExpenseReport").
'<br><br>';
725 $uploadform .= img_picto(
'',
'user',
'class="pictofixedwidth"');
727 $uploadform .= $form->select_dolusers(
GETPOSTINT(
'userexpensereportid') > 0 ?
GETPOSTINT(
'userexpensereportid') : $user->id,
'userexpensereportid', $langs->transnoentitiesnoconv(
"User"), null, 0,
'hierarchyme',
'',
'', 0, 0,
'', 0,
'',
'maxwidth200 disableautoopen', 1);
730 $uploadform .=
'<br>';
732 $uploadform .= img_picto(
'',
'invoice',
'class="pictofixedwidth"');
733 $uploadform .= $form->select_type_fees(
GETPOSTINT(
'feetypeid') > 0 ?
GETPOSTINT(
'feetypeid') : -1,
'feetypeid', $langs->transnoentitiesnoconv(
"TypeFees"),
'maxwidth200 disableautoopen', 1, 1);
735 $uploadform .=
'<br>';
738 <small class="opacitymedium">'.$langs->trans(
"OrClickToSelectAFile").
'...</small>
746 $langs->load(
"salaries");
748 <div id="userpayroll" class="flex-item flex-item-uploadfile">'.img_picto(
'',
'salary',
'class="fa-2x"').
'<br>
749 <div>'.$langs->trans(
"UserPaySlip").
'<br><br>';
751 $uploadform .= img_picto(
'',
'user',
'class="pictofixedwidth"');
752 $uploadform .= $form->select_dolusers(
GETPOSTINT(
'usersalaryid') > 0 ?
GETPOSTINT(
'usersalaryid') : -1,
'usersalaryid', $langs->transnoentitiesnoconv(
"Employee"), null, 0,
'hierarchyme',
'',
'', 0, 0,
'', 0,
'',
'maxwidth200 disableautoopen', 1);
754 $uploadform .=
'<br>';
757 <small class="opacitymedium">'.$langs->trans(
"OrClickToSelectAFile").
'...</small>
764 $langs->loadLangs(array(
"taxes",
"compta"));
766 <div id="socialcontribution" class="flex-item flex-item-uploadfile">'.img_picto(
'',
'invoice',
'class="fa-2x"').
'<br>
767 <div>'.$langs->trans(
"SocialContribution").
'<br><br>';
769 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsocialcontrib.class.php';
772 $uploadform .= img_picto(
'',
'invoice',
'class="pictofixedwidth"');
773 $uploadform .= $formsocialcontrib->select_type_socialcontrib(
GETPOST(
'socialcontrib',
'alpha') ?
GETPOSTINT(
'socialcontrib') : -1,
'socialcontrib', $langs->transnoentities(
"TypeContrib"), 0, 0,
'minwidth150 maxwidth200 disableautoopen', 0, 1);
775 $uploadform .=
'<br>';
777 $uploadform .= img_picto(
'',
'user',
'class="pictofixedwidth"');
778 $uploadform .= $form->select_dolusers(
GETPOSTINT(
'usertaxid') > 0 ?
GETPOSTINT(
'usertaxid') : -1,
'usertaxid', $langs->transnoentitiesnoconv(
"Employee"), null, 0,
'hierarchyme',
'',
'', 0, 0,
'', 0,
'',
'maxwidth200 disableautoopen', 1);
781 <small class="opacitymedium">'.$langs->trans(
"OrClickToSelectAFile").
'...</small>
786 $uploadform .=
'</div>';
792$parameters = array(
'uploadform' => $uploadform);
793$reshook = $hookmanager->executeHooks(
'printUploadForm', $parameters);
794if (empty($reshook)) {
795 $uploadform .= $hookmanager->resPrint;
797 $uploadform = $hookmanager->resPrint;
800$uploadform .=
'<br>';
803if ($action ==
'uploadfile' || $action ==
'showsummary') {
809.blink { animation: blinkerdots 1s linear infinite; }
810@keyframes blinkerdots { 50% { opacity: 0; } }
813 print
'<div class="'.($action ==
'showsummary' ?
'green' :
'neutral').
'" style="padding-left: 20px; padding-right: 20px;'.($action ==
'showsummary' ?
' border-left: solid 5px #118822;' :
'').
'">';
815 print
'<div class="marginbottom">';
816 if ($action ==
'showsummary') {
819 $filenamefordisplay = (string)
GETPOST(
'displayedfilename',
'alphanohtml');
820 if ($filenamefordisplay ===
'' || preg_match(
'/^upload_page-/', $filenamefordisplay)) {
821 $filenamefordisplay = preg_replace(
'/^upload_page-[a-z_]+(-uid\d+|-thiid\d+|-pid\d+|-erid\d+|-salid\d+)+-/',
'', (
string)
GETPOST(
'originalfilename',
'alphanohtml'));
823 print $langs->trans(
"AIProcessingDocumentPleaseWait",
dol_trunc($filenamefordisplay, 32,
'middle'), $ai->getApiService());
826 $processingduration =
GETPOSTFLOAT(
'processingduration');
827 if ($processingduration <= 0) {
829 if (preg_match(
'/^upload_page-[a-z_]+-uid'.((
int) $user->id).
'-/', $fileforduration)
830 &&
dol_is_file($upload_dir.
'/'.$fileforduration) &&
dol_is_file($upload_dir.
'/'.$fileforduration.
'.json')) {
831 $processingduration =
dol_filemtime($upload_dir.
'/'.$fileforduration.
'.json') -
dol_filemtime($upload_dir.
'/'.$fileforduration);
834 if ($processingduration > 0) {
835 print
'<br><span id="ajax-progress-message">'.$langs->trans(
"AIProcessingDocumentAnalyzingComplete", sprintf(
'%.1f', $processingduration)).
'</span>';
838 print $langs->trans(
"AIProcessingDocumentPleaseWait",
dol_trunc($uploadedfilename, 32,
'middle'), $ai->getApiService());
839 print
'<br><span id="ajax-progress-message">'.$langs->trans(
"AIProcessingDocumentConvertingIntoText", $converternamefortext).
'</span><span class="blink"> ...</span>';
844 print
'<div class="progress" title="80%">
845 <div class="progress-bar" role="progressbar" style="width: '.($action ==
'showsummary' ?
'100' :
'0').
'%" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100"></div>
852if ($action ==
'uploadfile') {
855 if (!empty($ajaxFileUrl)) {
857 $(document).ready(function() {
858 $("#form-result-back").on("click", function() {
859 window.location.href = $(this).data("url");
862 var ajaxUrlBase = \''.dol_escape_js($ajaxFileUrl).
'\';
863 var timestartprocessing = Date.now();
865 console.log(\
'Call ajaxFileUrl (step converttotext): \'.concat(ajaxUrlBase, "&step=converttotext"));
867 url: ajaxUrlBase.concat("&step=converttotext"),
870 beforeSend: function() {
871 $(".progress-bar").css("width", "25%");
873 success: function(data, textStatus, jqXHR) {
874 if (jqXHR.status === 200) {
875 // The conversion of the file into text is complete, we can ask the AI to analyze it
876 console.log("Conversion of the file into text complete, call the analysis");
877 $("#ajax-progress-message").text(\''.
dol_escape_js($langs->trans(
"AIProcessingDocumentAskingAnalyze", $modelforanalysis)).
'\');
878 $(
".progress-bar").css(
"width",
"60%");
880 url: ajaxUrlBase.concat(
"&step=analyze"),
883 success: function(data, textStatus, jqXHR) {
884 if (jqXHR.status === 200) {
886 console.log(
"Fill the #ajax-result with json result");
889 $(
"#ajax-result").val(btoa(Array.from(
new TextEncoder().
encode(JSON.stringify(data,
null, 2)), function (c) {
return String.fromCharCode(c); }).join(
"")));
890 $(
".progress-bar").css(
"width",
"100%");
892 $(
"span.blink").remove();
893 var durationofprocessing = ((Date.now() - timestartprocessing) / 1000).toFixed(1);
895 $(
"#ajax-progress-message").text(\
''.
dol_escape_js($langs->trans(
"AIProcessingDocumentAnalyzingComplete",
'%s')).
'\'.replace(
"%s", durationofprocessing));
896 $(
"#processing-duration").val(durationofprocessing);
899 $(
"#form-result").submit();
901 console.log(
"We received an error");
902 $(
"span.blink").remove();
905 $(
"#ajax-result-message").html(
"<div class=\"error\">Error: HTTP status " + jqXHR.status +
"</div>");
907 $(
"#form-result-submit").hide();
908 $(
"#form-result-back").show();
911 error:
function(jqXHR, textStatus, errorThrown) {
913 console.log(
"We received an error");
914 $(
"span.blink").remove();
916 var errormsg = (jqXHR.responseJSON && jqXHR.responseJSON.errors) ? jqXHR.responseJSON.errors.join(
" - ") : (jqXHR.responseText || errorThrown ||
"Unknown error");
917 $(
"#ajax-result-message").html($(
"<div class=\"error\"></div>").text(
"Error: " + errormsg));
918 $(
".progress-bar").css(
"width",
"100%");
920 $(
"#form-result-submit").hide();
921 $(
"#form-result-back").show();
925 console.log(
"We received an error");
926 $(
"span.blink").remove();
929 $(
"#ajax-result-message").html(
"<div class=\"error\">Error: HTTP status " + jqXHR.status +
"</div>");
931 $(
"#form-result-submit").hide();
932 $(
"#form-result-back").show();
935 error:
function(jqXHR, textStatus, errorThrown) {
937 console.log(
"We received an error");
938 $(
"span.blink").remove();
940 var errormsg = (jqXHR.responseJSON && jqXHR.responseJSON.errors) ? jqXHR.responseJSON.errors.join(
" - ") : (jqXHR.responseText || errorThrown ||
"Unknown error");
941 $(
"#ajax-result-message").html($(
"<div class=\"error\"></div>").text(
"Error: " + errormsg));
942 $(
".progress-bar").css(
"width",
"100%");
944 $(
"#form-result-submit").hide();
945 $(
"#form-result-back").show();
952 // Example of JSON result when importing a supplier PDF invoice
956 "invoice_number": "MSTRL-API-1234-001",
957 "invoice_reference": "Pro - Annual",
958 "issue_date": "2026-08-21",
959 "due_date": "2026-08-21",
962 "description": "0 jours"
964 "organization": "MyBigCompany"
967 "name": "Mistral AI SAS",
969 "street": "15, rue des Halles",
970 "postal_code": "75001",
974 "vat_number": "FR95952418325",
976 "siren": "952 418 325",
977 "capital": "19,189.04 €",
980 "email": "no-reply@mistral.ai",
981 "contact_url": "https://help.mistral.ai/en"
984 "name": "MyBigCompany",
986 "street": "1 rue de la paix",
987 "postal_code": "75000",
991 "vat_number": "FR012345678901",
992 "email": "contact@mybigcompany.com"
996 "description": "Fee for use- August",
997 "service": "Pro - Annual",
1001 "total_excluding_tax": 143.9,
1002 "total_including_tax": 172.68,
1003 "period_start": "2026-08-21",
1004 "period_end": "2027-08-20"
1008 "subtotal_excluding_tax": 143.9,
1012 "description": "EU FR Standard (20.0% sur 143,90 €)"
1014 "total_including_tax": 172.68
1017 "due_date": "2026-08-21",
1018 "amount_due": 172.68,
1025 "content": "Mistral AI - SAS au capital de 19,189.04€ - 952 418 325 R.C.S. Paris"
1029 "content": "For any inquiry, please refer to https://help.mistral.ai/en"
1036 print '<form
class=
"" id=
"form-result" method=
"POST" action=
"'.dolBuildUrl($_SERVER["PHP_SELF
"]).'">
';
1037 print '<input
type=
"hidden" name=
"token" value=
"'.newToken().'">
';
1038 print '<input
type=
"hidden" name=
"action" value=
"showsummary">
';
1039 print '<input
type=
"hidden" name=
"modulepart" value=
"'.$modulepart.'">
';
1040 print '<input
type=
"hidden" name=
"socid" value=
"'.$socid.'">
';
1041 print '<input
type=
"hidden" name=
"prodid" value=
"'.($prodid > 0 ? 'idprod_'.$prodid : '').'">
';
1042 print '<input
type=
"hidden" name=
"usersalaryid" value=
"'.GETPOSTINT('usersalaryid').'">
';
1043 print '<input
type=
"hidden" name=
"socialcontrib" value=
"'.GETPOSTINT('socialcontrib').'">
';
1044 print '<input
type=
"hidden" name=
"usertaxid" value=
"'.GETPOSTINT('usertaxid').'">
';
1045 print '<input
type=
"hidden" name=
"userexpensereportid" value=
"'.GETPOSTINT('userexpensereportid').'">
';
1046 print '<input
type=
"hidden" name=
"feetypeid" value=
"'.$feetypeid.'">
';
1047 print '<input
type=
"hidden" name=
"originalfilename" value=
"'.$fullnewname.'">
';
1048 print '<input
type=
"hidden" name=
"jsonstring" id=
"ajax-result" value=
"">
'; // Fill by the ajax answer with the JSON encoded in base64
1049 print '<input
type=
"hidden" name=
"displayedfilename" value=
"'.dolPrintHTMLForAttribute($uploadedfilename).'">
';
1050 print '<input
type=
"hidden" name=
"processingduration" id=
"processing-duration" value=
"">
'; // Fill by the JS at the end of the processing
1051 print '<div
id=
"ajax-result-message"></div>
';
1052 if ($action == 'uploadfile
') {
1054 // The buttons are hidden until the end of the ajax call: Next is shown on success, Go back on error
1055 print '<input
type=
"submit" name=
"form-result-submit" id=
"form-result-submit" class=
"button" style=
"display: none" value=
"'.$langs->trans("Next
").'">
';
1056 print '<input
type=
"button" name=
"form-result-back" id=
"form-result-back" class=
"button" style=
"display: none" value=
"'.$langs->trans("GoBack
").'" data-url=
"'.dolPrintHTMLForAttributeUrl($_SERVER["PHP_SELF
"]).'">
';
1058 print '</form>
'."\n";
1062if ($action == 'showsummary
') {
1063 print '<form
class=
"" id=
"summary-result" method=
"POST" action=
"'.dolBuildUrl($_SERVER["PHP_SELF
"]).'">
';
1064 // On wide screens (>= 1280), the summary and the preview of the file are shown side by side,
1065 // both stretched to the height of the tallest one
1067@media (min-width: 1280px) {
1068 #summary-result { display: flex; flex-wrap: wrap; align-items: stretch; }
1069 #divsummary { flex: 1 1 58%; display: flex; }
1070 #divpreview { flex: 1 1 40%; }
1073 print '<input
type=
"hidden" name=
"token" value=
"'.newToken().'">
';
1074 print '<input
type=
"hidden" name=
"action" value=
"addobject">
';
1075 print '<input
type=
"hidden" name=
"modulepart" value=
"'.$modulepart.'">
';
1076 print '<input
type=
"hidden" name=
"originalfilename" value=
"'.dolPrintHTMLForAttribute(GETPOST('originalfilename', 'alphanohtml')).'">
';
1077 print '<div
id=
"ajax-result-message"></div>
';
1080 //print load_fiche_titre('Summary
', '', 'upload
');
1082 print '<div
id=
"divsummary">
';
1083 print '<div
class=
"neutral" style=
"margin-top: 0px; margin-bottom: 0px">
';
1085 print '<input
type=
"hidden" name=
"token" value=
"'.newToken().'">
';
1087 // Read the result of the AI service from the JSON cache file saved by ajaxuploadpage.php, or from the posted value as fallback
1088 $jsonstring = (string) base64_decode(GETPOST('jsonstring
', 'alpha
'), true); // The posted JSON is encoded in base64. Strict mode returns false (so '') on invalid chars.
1089 $filejsoncache = dol_sanitizeFileName(GETPOST('originalfilename
', 'alphanohtml
'));
1090 if (preg_match('/^upload_page-[a-z_]+-uid
'.((int) $user->id).'-/
', $filejsoncache) && dol_is_file($upload_dir.'/
'.$filejsoncache.'.json
')) {
1091 $jsonstring = (string) file_get_contents($upload_dir.'/
'.$filejsoncache.'.json
');
1095 if (!empty($jsonstring)) { // This can happen if we resubmit a page after doc was created, both jsonsting and cache file does not exists anymore.
1096 $json = json_decode($jsonstring, true);
1097 if (json_last_error() === JSON_ERROR_NONE) {
1098 print '<!-- JSON
string -->
';
1099 // Insert a space between consecutive dashes so content can't close the HTML comment (
"-->" or
"--!>")
1100 print
'<!-- '.preg_replace(
'/-(?=-)/',
'- ', $jsonstring).
' -->';
1103 print
'Failed to decode the result of the AI service. Error: '.dolPrintHTML(json_last_error_msg());
1105 print
'Result: '.dolPrintHTML($jsonstring);
1112 if ($modulepart ==
'invoice_supplier') {
1113 $langs->loadLangs(array(
"bills",
"companies",
"products"));
1116 $invoiceindoc = $ai->decodeJsonIntoArray(is_array($json) ? $json : array(),
'supplier_invoice');
1119 if (empty($invoiceindoc[
'issue_date']) && !empty($invoiceindoc[
'due_date'])) {
1120 $invoiceindoc[
'issue_date'] = $invoiceindoc[
'due_date'];
1126 print
'<div id="supplierinvoice" class="">';
1131 $nameindoc = (string) $invoiceindoc[
'vendor_name'];
1132 $addressindoc = (string) $invoiceindoc[
'vendor_address'];
1133 $idprof1indoc = (string) $invoiceindoc[
'vendor_profid1'];
1134 $idprof2indoc = (string) $invoiceindoc[
'vendor_profid2'];
1135 $emailindoc = (string) $invoiceindoc[
'vendor_email'];
1136 $vatnumberindoc = (string) $invoiceindoc[
'vendor_vat_number'];
1137 $phoneindoc = (string) $invoiceindoc[
'vendor_phone'];
1138 $zipindoc = (string) $invoiceindoc[
'vendor_zip'];
1139 $townindoc = (string) $invoiceindoc[
'vendor_town'];
1140 $countryindoc = (string) $invoiceindoc[
'vendor_country'];
1144 $tmpthirdparty =
new Societe($db);
1145 print img_picto(
'',
'company',
'class="pictofixedwidth"').$langs->trans(
"ThirdParty").
'<br>';
1151 $result = $tmpthirdparty->findNearest(0, $nameindoc,
'',
'', $idprof1indoc, $idprof2indoc,
'',
'',
'',
'', $emailindoc, $nameindoc, 0, 0, $vatnumberindoc);
1154 $tmpthirdparty->fetch($result);
1158 print
'<span class="opacitymedium">'.$langs->trans(
"KeyDataFoundInDocument").
' :</span> ';
1160 if (!empty($addressindoc)) {
1161 $s .=
', '.$addressindoc;
1164 print
'<span class="warning">'.$langs->trans(
"NoDataRelatedTo").
'</span>';
1168 if (empty($tmpthirdparty->id)) {
1170 print
'<span class="warning">'.$langs->trans(
"NotFoundInDatabase").
'</span><br>';
1172 print $form->select_company($socid,
'socid',
'((s.fournisseur:=:1) AND (s.status:=:1))',
'ChooseTheThirdPartyTouse', 1, 0, array(), 0,
'minwidth300 maxwidth400 disableautoopen',
'',
'', 1, array(),
false, array(),
'supplier');
1174 if ($user->hasRight(
'societe',
'creer')) {
1175 $langs->load(
"companies");
1177 $paramsbacktosummary = array(
'action' =>
'showsummary',
'modulepart' => $modulepart,
'originalfilename' =>
GETPOST(
'originalfilename',
'alphanohtml'),
'socid' =>
'--IDFORBACKTOPAGE--');
1178 if (
GETPOST(
'prodid',
'alpha') !==
'') {
1179 $paramsbacktosummary[
'prodid'] =
GETPOST(
'prodid',
'alpha');
1181 if (
GETPOST(
'supplierref',
'alphanohtml') !==
'') {
1182 $paramsbacktosummary[
'supplierref'] =
GETPOST(
'supplierref',
'alphanohtml');
1185 $paramstocreatethirdparty = array();
1186 if ($nameindoc !==
'') {
1187 $paramstocreatethirdparty[
'name'] = $nameindoc;
1189 if ($addressindoc !==
'') {
1190 $paramstocreatethirdparty[
'address'] = $addressindoc;
1192 if ($phoneindoc !==
'') {
1193 $paramstocreatethirdparty[
'phone'] = $phoneindoc;
1195 if ($emailindoc !==
'') {
1196 $paramstocreatethirdparty[
'email'] = $emailindoc;
1198 if ($vatnumberindoc !==
'') {
1199 $paramstocreatethirdparty[
'tva_intra'] = $vatnumberindoc;
1201 if ($idprof1indoc !==
'') {
1202 $paramstocreatethirdparty[
'idprof1'] = $idprof1indoc;
1204 if ($idprof2indoc !==
'') {
1205 $paramstocreatethirdparty[
'idprof2'] = $idprof2indoc;
1207 if ($zipindoc !==
'') {
1208 $paramstocreatethirdparty[
'zipcode'] = $zipindoc;
1210 if ($townindoc !==
'') {
1211 $paramstocreatethirdparty[
'town'] = $townindoc;
1213 if ($countryindoc !==
'') {
1214 $countryidindoc = (int)
dol_getIdFromCode($db, $countryindoc,
'c_country',
'code',
'rowid');
1215 if (empty($countryidindoc)) {
1216 $countryidindoc = (int)
dol_getIdFromCode($db, $countryindoc,
'c_country',
'label',
'rowid');
1218 if (!empty($countryidindoc)) {
1219 $paramstocreatethirdparty[
'country_id'] = $countryidindoc;
1222 $paramstocreatethirdparty = array_merge(array(
'action' =>
'create',
'client' => 0,
'fournisseur' => 1,
'backtopage' =>
dolBuildUrl($_SERVER[
"PHP_SELF"], $paramsbacktosummary)), $paramstocreatethirdparty);
1223 print
' <a href="'.dolBuildUrl(DOL_URL_ROOT.
'/societe/card.php', $paramstocreatethirdparty).
'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans(
"AddThirdParty").
'"></span></a>';
1226 print
'<span class="valignmiddle">'.$langs->trans(
"WillUse").
'</span> ';
1227 print $tmpthirdparty->getNomUrl(1);
1228 print
'<input type="hidden" name="socid" value="'.$tmpthirdparty->id.
'">';
1233 print
'<br><br><hr style="margin: 0px"><br>';
1238 $nameprodindoc = $invoiceindoc[
'items'][0][
'description'];
1239 if (empty($nameprodindoc) && !empty($invoiceindoc[
'items'][0][
'service'])) {
1240 $nameprodindoc = $invoiceindoc[
'items'][0][
'service'];
1243 if (!empty($invoiceindoc[
'lines']) && is_array($invoiceindoc[
'lines'])) {
1244 $nbofitems = count($invoiceindoc[
'lines']);
1249 $tmpproduct =
new Product($db);
1250 print img_picto(
'',
'product',
'class="pictofixedwidth"').$langs->trans(
"Product").
'<br>';
1256 $tmpproduct->fetch($prodid);
1257 if (empty($amount_ttc)) {
1267 print
'<span class="opacitymedium">'.$langs->trans(
"KeyDataFoundInDocument").
' :</span> ';
1268 $s = $nameprodindoc;
1269 if (!empty($nbofitems)) {
1270 $s .= ($s ?
', ' :
'').$langs->trans(
"NbOfLines").
': '.$nbofitems;
1273 print
'<span class="warning">'.$langs->trans(
"NoDataRelatedTo").
'</span>';
1277 if (empty($tmpproduct->id)) {
1278 print $form->select_produits_fournisseurs(0, ($prodid > 0 ?
'idprod_'.$prodid : $prodid),
'prodid',
'',
'', array(), 1, 1,
'minwidth300 maxwidth400 disableautoopen', $langs->trans(
"ChooseTheProductOrServiceTouse"), 1);
1282 $addproducton = (
isModEnabled(
'product') && $user->hasRight(
'produit',
'creer'));
1283 $addserviceon = (
isModEnabled(
'service') && $user->hasRight(
'service',
'creer'));
1286 $paramsbacktosummary = array(
'action' =>
'showsummary',
'modulepart' => $modulepart,
'originalfilename' =>
GETPOST(
'originalfilename',
'alphanohtml'));
1288 $paramsbacktosummary[
'socid'] =
GETPOSTINT(
'socid');
1290 if (
GETPOST(
'supplierref',
'alphanohtml') !==
'') {
1291 $paramsbacktosummary[
'supplierref'] =
GETPOST(
'supplierref',
'alphanohtml');
1293 $urlbacktocancel =
dolBuildUrl($_SERVER[
"PHP_SELF"], $paramsbacktosummary);
1294 $paramsbacktosummary[
'prodid'] =
'idprod_--IDFORBACKTOPAGE--';
1295 $urlbacktoobject =
dolBuildUrl($_SERVER[
"PHP_SELF"], $paramsbacktosummary);
1296 if ($addproducton || $addserviceon) {
1297 $langs->load(
"products");
1298 if ($addproducton && $addserviceon) {
1299 print
' <div id="dropdownAddProductAndService" class="dropdown inline-block">';
1300 print
'<a href="#" class="dropdown-toggle" data-toggle="dropdown" role="button" id="dropdownAddProductAndServiceLink" aria-haspopup="true" aria-expanded="false">';
1301 print
'<span class="fa fa-plus-circle valignmiddle paddingleft"></span>';
1303 print
'<div class="dropdown-menu" aria-labelledby="dropdownAddProductAndServiceLink" style="top:auto; left:auto;">';
1304 print
'<a class="dropdown-item" href="'.DOL_URL_ROOT.
'/product/card.php?action=create&type=0&backtopage='.urlencode($urlbacktoobject).
'&backtopageforcancel='.urlencode($urlbacktocancel).
'"> '.$langs->trans(
"NewProduct").
'</a>';
1305 print
'<a class="dropdown-item" href="'.DOL_URL_ROOT.
'/product/card.php?action=create&type=1&backtopage='.urlencode($urlbacktoobject).
'&backtopageforcancel='.urlencode($urlbacktocancel).
'"> '.$langs->trans(
"NewService").
'</a>';
1308 print
'<script nonce="'.getNonce().
'">
1309 jQuery(document).ready(function() {
1310 jQuery("#dropdownAddProductAndService .dropdown-toggle").on("click", function(event) {
1311 console.log("toggle addproduct dropdown");
1312 event.preventDefault();
1313 jQuery("#dropdownAddProductAndService").toggleClass("open");
1315 // Close the dropdown when clicking outside of it
1316 jQuery(document).on("click", function(event) {
1317 if (jQuery(event.target).closest("#dropdownAddProductAndService").length == 0) {
1318 jQuery("#dropdownAddProductAndService").removeClass("open");
1323 } elseif ($addproducton) {
1324 print
' <a href="'.DOL_URL_ROOT.
'/product/card.php?action=create&type=0&backtopage='.urlencode($urlbacktoobject).
'&backtopageforcancel='.urlencode($urlbacktocancel).
'" title="'.
dol_escape_htmltag($langs->trans(
"NewProduct")).
'"><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>';
1326 print
' <a href="'.DOL_URL_ROOT.
'/product/card.php?action=create&type=1&backtopage='.urlencode($urlbacktoobject).
'&backtopageforcancel='.urlencode($urlbacktocancel).
'" title="'.
dol_escape_htmltag($langs->trans(
"NewService")).
'"><span class="fa fa-plus-circle valignmiddle paddingleft"></span></a>';
1330 print $langs->trans(
"WillUse").
' ';
1331 print $tmpproduct->getNomUrl(1);
1332 print
'<input type="hidden" name="prodid" value="idprod_'.$tmpproduct->id.
'">';
1336 print $langs->trans(
"VATRate").
' ';
1337 print
'<input type="text" class="width75 right" name="vat_rate" id="vat_rate" value="'.$vat_rate.
'"> %';
1340 print $langs->trans(
"TotalTTC").
' ';
1341 print
'<input type="text" class="width100 right" name="amount_ttc" id="amount_ttc" value="'.$amount_ttc.
'">';
1344 print
'<br><br><hr style="margin: 0px"><br>';
1351 print img_picto(
'',
'supplier_invoice',
'class="pictofixedwidth"').$langs->trans(
"SupplierInvoice").
'<br>';
1353 print
'<span class="opacitymedium">'.$langs->trans(
"KeyDataFoundInDocument").
' :</span> ';
1354 $tmpvalue = array();
1355 $invoiceindoc[
'supplierref'] ? $tmpvalue[] = $langs->transnoentitiesnoconv(
"InvoiceRef").
': '.$invoiceindoc[
'supplierref'] :
'';
1356 $invoiceindoc[
'issue_date'] ? $tmpvalue[] = $langs->transnoentitiesnoconv(
"DateInvoice").
': '.
dol_print_date($invoiceindoc[
'issue_date'],
'day',
'tzuserrel') :
'';
1357 $invoiceindoc[
'due_date'] ? $tmpvalue[] = $langs->transnoentitiesnoconv(
"DateDue").
': '.
dol_print_date($invoiceindoc[
'due_date'],
'day',
'tzuserrel') :
'';
1358 $invoiceindoc[
'currency_code'] ? $tmpvalue[] = $langs->transnoentitiesnoconv(
"Currency").
': '.$invoiceindoc[
'currency_code'] :
'';
1359 $invoiceindoc[
'invoice_label'] ? $tmpvalue[] = $langs->transnoentitiesnoconv(
"Label").
': '.$invoiceindoc[
'invoice_label'] :
'';
1361 $s = implode(
', ', $tmpvalue);
1363 print
'<span class="warning">'.$langs->trans(
"NoDataRelatedTo").
'</span>';
1367 if (!empty($invoiceindoc[
'supplierref'])) {
1371 $sql =
"SELECT rowid, total_ttc FROM " . $db->prefix() .
"facture_fourn";
1372 $sql .=
" WHERE ref_supplier = '" . $db->escape($invoiceindoc[
'supplierref']) .
"'";
1373 $sql .=
" AND fk_soc = " . ((int) $tmpthirdparty->id);
1374 $sql .=
" AND entity IN (" .
getEntity(
'facture_fourn') .
")";
1376 $resql = $db->query($sql);
1378 dol_syslog(
"SQL Error " . $db->lasterror(), LOG_ERR);
1381 $obj = $db->fetch_object($resql);
1383 $tmpinvoice->fetch($obj->rowid);
1389 if (empty($tmpinvoice->id)) {
1390 print $langs->trans(
"InvoiceWillBeCreated");
1392 $supplierref = (
GETPOSTISSET(
'supplierref') ?
GETPOST(
'supplierref',
'alphanohtml') : (string) $invoiceindoc[
'supplierref']);
1394 print
'<br>'.$langs->trans(
"RefSupplier").
' ';
1395 print
'<input type="text" class="minwidth150" name="supplierref" id="supplierref" value="'.dolPrintHTMLForAttribute($supplierref).
'">';
1397 print
'<input type="hidden" name="due_date" value="'.$invoiceindoc[
'due_date'].
'">';
1398 print
'<input type="hidden" name="issue_date" value="'.$invoiceindoc[
'issue_date'].
'">';
1399 print
'<input type="hidden" name="currency_code" value="'.$invoiceindoc[
'currency_code'].
'">';
1400 print
'<input type="hidden" name="invoice_label" value="'.$invoiceindoc[
'invoice_label'].
'">';
1403 print str_replace(
'__INVOICELINK__', $tmpinvoice->getNomUrl(1), $langs->trans(
"InvoiceSeemsToAlreadyExist", $tmpinvoice->ref_supplier,
'__INVOICELINK__'));
1404 print
'<input type="hidden" name="invoiceid" value="'.$tmpinvoice->id.
'">';
1411 print
'<br><br><center><input type="submit" name="submit" class="button" value="'.$langs->trans(empty($tmpinvoice->id) ?
"CreateBill" :
"AttachFileToExistingInvoice").
'"></center>';
1413 } elseif ($modulepart ==
'salaries') {
1414 $langs->loadLangs(array(
"salaries",
"hrm",
"compta",
"bills"));
1417 $salaryindoc = $ai->decodeJsonIntoArray(is_array($json) ? $json : array(),
'salary');
1420 $arrayofdates = array();
1421 foreach (array(
'period_start',
'period_end',
'payment_date') as $keydate) {
1422 $arrayofdates[$keydate] =
'';
1424 if (!empty($salaryindoc[$keydate]) && preg_match(
'/^(\d{4})-(\d{2})-(\d{2})$/',
dol_print_date($salaryindoc[$keydate],
'%Y-%m-%d',
'tzuserrel'), $reg)) {
1425 $arrayofdates[$keydate] =
dol_mktime(12, 0, 0, (
int) $reg[2], (
int) $reg[3], (
int) $reg[1]);
1431 $amount =
GETPOSTISSET(
'amount') ?
GETPOST(
'amount',
'alpha') : (is_numeric($salaryindoc[
'net_to_pay'] ?? null) ?
price((float) $salaryindoc[
'net_to_pay']) :
'');
1432 $label =
GETPOSTISSET(
'label') ?
GETPOST(
'label',
'alphanohtml') : $langs->transnoentitiesnoconv(
"Salary").($datesp ?
' '.
dol_print_date($datesp,
'%m/%Y') :
'');
1435 print
'<div id="userpayroll" class="">';
1438 print img_picto(
'',
'user',
'class="pictofixedwidth"').$langs->trans(
"Employee").
'<br>';
1439 print
'<span class="opacitymedium">'.$langs->trans(
"KeyDataFoundInDocument").
' :</span> ';
1440 if (empty($salaryindoc[
'employee_name'])) {
1441 print
'<span class="warning">'.$langs->trans(
"NoDataRelatedTo").
'</span>';
1443 print dolPrintLabel($salaryindoc[
'employee_name']);
1446 print $langs->trans(
"WillUse").
' ';
1447 print $form->select_dolusers(
GETPOSTINT(
'usersalaryid') > 0 ?
GETPOSTINT(
'usersalaryid') : -1,
'usersalaryid', $langs->transnoentitiesnoconv(
"Employee"), null, 0,
'hierarchyme',
'',
'', 0, 0,
'', 0,
'',
'maxwidth200 disableautoopen', 1);
1450 print
'<br><br><hr style="margin: 0px"><br>';
1454 print img_picto(
'',
'salary',
'class="pictofixedwidth"').$langs->trans(
"Salary").
'<br>';
1455 print
'<span class="opacitymedium">'.$langs->trans(
"KeyDataFoundInDocument").
' :</span> ';
1456 $tmpvalue = array();
1457 if ($arrayofdates[
'period_start'] && $arrayofdates[
'period_end']) {
1458 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Period").
': '.
dol_print_date($arrayofdates[
'period_start'],
'day').
' - '.
dol_print_date($arrayofdates[
'period_end'],
'day');
1460 if ($arrayofdates[
'payment_date']) {
1461 $tmpvalue[] = $langs->transnoentitiesnoconv(
"DatePayment").
': '.
dol_print_date($arrayofdates[
'payment_date'],
'day');
1463 if (is_numeric($salaryindoc[
'gross_salary'] ??
null)) {
1464 $tmpvalue[] = $langs->transnoentitiesnoconv(
"GrossSalary").
': '.
price((
float) $salaryindoc[
'gross_salary']);
1466 if (is_numeric($salaryindoc[
'net_to_pay'] ??
null)) {
1467 $tmpvalue[] = $langs->transnoentitiesnoconv(
"NetToBePaid").
': '.
price((
float) $salaryindoc[
'net_to_pay']);
1469 if (!empty($salaryindoc[
'currency_code'])) {
1470 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Currency").
': '.dolPrintLabel($salaryindoc[
'currency_code']);
1472 $s = implode(
', ', $tmpvalue);
1474 print
'<span class="warning">'.$langs->trans(
"NoDataRelatedTo").
'</span>';
1478 print $langs->trans(
"SalaryWillBeCreated").
'<br>';
1480 print $langs->trans(
"Label").
' ';
1481 print
'<input type="text" class="minwidth300" name="label" id="label" value="'.dolPrintHTMLForAttribute($label).
'"><br>';
1482 print $langs->trans(
"DateStartPeriod").
' ';
1483 print $form->selectDate($datesp,
'datesp', 0, 0, 1,
'summary-result', 1, 0);
1485 print $langs->trans(
"DateEndPeriod").
' ';
1486 print $form->selectDate($dateep,
'dateep', 0, 0, 1,
'summary-result', 1, 0);
1488 print $langs->trans(
"NetToBePaid").
' ';
1489 print
'<input type="text" class="width100 right" name="amount" id="amount" value="'.dolPrintHTMLForAttribute((
string) $amount).
'">';
1490 if (is_numeric($salaryindoc[
'gross_salary'] ??
null)) {
1491 print
'<input type="hidden" name="gross_salary" value="'.((float) $salaryindoc[
'gross_salary']).
'">';
1498 print
'<br><br><center><input type="submit" name="submit" class="button" value="'.$langs->trans(
"Create").
'"></center>';
1500 } elseif ($modulepart ==
'chargesociales') {
1501 $langs->loadLangs(array(
"compta",
"hrm",
"bills"));
1502 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formsocialcontrib.class.php';
1506 $taxindoc = $ai->decodeJsonIntoArray(is_array($json) ? $json : array(),
'social_contribution');
1509 $arrayofdates = array();
1510 foreach (array(
'period_start',
'period_end',
'due_date') as $keydate) {
1511 $arrayofdates[$keydate] =
'';
1513 if (!empty($taxindoc[$keydate]) && preg_match(
'/^(\d{4})-(\d{2})-(\d{2})$/',
dol_print_date($taxindoc[$keydate],
'%Y-%m-%d',
'tzuserrel'), $reg)) {
1514 $arrayofdates[$keydate] =
dol_mktime(12, 0, 0, (
int) $reg[2], (
int) $reg[3], (
int) $reg[1]);
1520 $amount =
GETPOSTISSET(
'amount') ?
GETPOST(
'amount',
'alpha') : (is_numeric($taxindoc[
'amount'] ?? null) ?
price((float) $taxindoc[
'amount']) :
'');
1521 $label =
GETPOSTISSET(
'label') ?
GETPOST(
'label',
'alphanohtml') : trim((string) ($taxindoc[
'label'] ??
'').(!empty($taxindoc[
'organization']) && ($taxindoc[
'organization'] != ($taxindoc[
'label'] ??
'')) ?
' - '.$taxindoc[
'organization'] :
''));
1524 print
'<div id="socialcontribution" class="">';
1526 print img_picto(
'',
'bill',
'class="pictofixedwidth"').$langs->trans(
"SocialContribution").
'<br>';
1527 print
'<span class="opacitymedium">'.$langs->trans(
"KeyDataFoundInDocument").
' :</span> ';
1528 $tmpvalue = array();
1529 if (!empty($taxindoc[
'organization'])) {
1530 $tmpvalue[] = dolPrintLabel($taxindoc[
'organization']);
1532 if (!empty($taxindoc[
'label'])) {
1533 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Label").
': '.dolPrintLabel($taxindoc[
'label']);
1535 if (!empty($taxindoc[
'reference'])) {
1536 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Ref").
': '.dolPrintLabel($taxindoc[
'reference']);
1538 if ($arrayofdates[
'period_start'] || $arrayofdates[
'period_end']) {
1539 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Period").
': '.
dol_print_date($arrayofdates[
'period_start'],
'day').
' - '.
dol_print_date($arrayofdates[
'period_end'],
'day');
1541 if ($arrayofdates[
'due_date']) {
1542 $tmpvalue[] = $langs->transnoentitiesnoconv(
"DateDue").
': '.
dol_print_date($arrayofdates[
'due_date'],
'day');
1544 if (is_numeric($taxindoc[
'amount'] ??
null)) {
1545 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Amount").
': '.
price((
float) $taxindoc[
'amount']);
1547 if (!empty($taxindoc[
'currency_code'])) {
1548 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Currency").
': '.dolPrintLabel($taxindoc[
'currency_code']);
1550 if (!empty($taxindoc[
'employee_name'])) {
1551 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Employee").
': '.dolPrintLabel($taxindoc[
'employee_name']);
1553 $s = implode(
', ', $tmpvalue);
1555 print
'<span class="warning">'.$langs->trans(
"NoDataRelatedTo").
'</span>';
1559 print $langs->trans(
"SocialContributionWillBeCreated").
'<br>';
1561 print $langs->trans(
"Type").
' ';
1562 print $formsocialcontrib->select_type_socialcontrib(
GETPOSTINT(
'socialcontrib') > 0 ?
GETPOSTINT(
'socialcontrib') : 0,
'socialcontrib', 1, 0, 1,
'minwidth200 maxwidth300', 0, 1);
1564 print $langs->trans(
"Label").
' ';
1565 print
'<input type="text" class="minwidth300" name="label" id="label" value="'.dolPrintHTMLForAttribute($label).
'"><br>';
1566 print $langs->trans(
"DateDue").
' ';
1567 print $form->selectDate($dateech,
'ech', 0, 0, 1,
'summary-result', 1, 0);
1569 print $langs->trans(
"PeriodEndDate").
' ';
1570 print $form->selectDate($dateperiod,
'period', 0, 0, 1,
'summary-result', 1, 0);
1572 print $langs->trans(
"Amount").
' ';
1573 print
'<input type="text" class="width100 right" name="amount" id="amount" value="'.dolPrintHTMLForAttribute((
string) $amount).
'"><br>';
1574 print $langs->trans(
"Employee").
' ';
1575 print $form->select_dolusers(
GETPOSTINT(
'usertaxid') > 0 ?
GETPOSTINT(
'usertaxid') : -1,
'usertaxid', 1, null, 0,
'hierarchyme',
'',
'', 0, 0,
'', 0,
'',
'maxwidth200 disableautoopen', 1);
1581 print
'<br><br><center><input type="submit" name="submit" class="button" value="'.$langs->trans(
"Create").
'"></center>';
1583 } elseif ($modulepart ==
'expensereport') {
1584 $langs->loadLangs(array(
"trips",
"hrm",
"bills"));
1587 $expenseindoc = $ai->decodeJsonIntoArray(is_array($json) ? $json : array(),
'expense');
1592 if (!empty($expenseindoc[
'date']) && preg_match(
'/^(\d{4})-(\d{2})-(\d{2})$/',
dol_print_date($expenseindoc[
'date'],
'%Y-%m-%d',
'tzuserrel'), $reg)) {
1593 $dateindoc =
dol_mktime(0, 0, 0, (
int) $reg[2], (
int) $reg[3], (
int) $reg[1]);
1597 $amount_ttc =
GETPOSTISSET(
'amount_ttc') ?
GETPOST(
'amount_ttc',
'alpha') : (is_numeric($expenseindoc[
'total_ttc'] ?? null) ?
price((float) $expenseindoc[
'total_ttc']) :
'');
1598 $vat_rate =
GETPOSTISSET(
'vat_rate') ?
GETPOST(
'vat_rate',
'alpha') : (is_numeric($expenseindoc[
'vat_rate'] ?? null) ?
price((float) $expenseindoc[
'vat_rate']) :
'');
1599 $comments =
GETPOSTISSET(
'comments') ?
GETPOST(
'comments',
'alphanohtml') : trim((string) ($expenseindoc[
'merchant'] ??
'').(!empty($expenseindoc[
'label']) ?
' - '.$expenseindoc[
'label'] :
''),
' -');
1600 $expenseuserid =
GETPOSTINT(
'userexpensereportid');
1603 print
'<div id="userexpensereport" class="">';
1606 print img_picto(
'',
'user',
'class="pictofixedwidth"').$langs->trans(
"Employee").
'<br>';
1607 print $langs->trans(
"WillUse").
' ';
1608 print $form->select_dolusers($expenseuserid > 0 ? $expenseuserid : -1,
'userexpensereportid', 1, null, 0,
'hierarchyme',
'',
'', 0, 0,
'', 0,
'',
'maxwidth200 disableautoopen', 1);
1611 print
'<br><br><hr style="margin: 0px"><br>';
1615 print img_picto(
'',
'expensereport',
'class="pictofixedwidth"').$langs->trans(
"ExpenseReportLine").
'<br>';
1616 print
'<span class="opacitymedium">'.$langs->trans(
"KeyDataFoundInDocument").
' :</span> ';
1617 $tmpvalue = array();
1618 if (!empty($expenseindoc[
'merchant'])) {
1619 $tmpvalue[] = dolPrintLabel($expenseindoc[
'merchant']);
1621 if (!empty($expenseindoc[
'label'])) {
1622 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Label").
': '.dolPrintLabel($expenseindoc[
'label']);
1624 if (!empty($expenseindoc[
'category'])) {
1625 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Type").
': '.dolPrintLabel($expenseindoc[
'category']);
1628 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Date").
': '.
dol_print_date($dateindoc,
'day');
1630 if (is_numeric($expenseindoc[
'vat_rate'] ??
null)) {
1631 $tmpvalue[] = $langs->transnoentitiesnoconv(
"VATRate").
': '.
vatrate((
string) $expenseindoc[
'vat_rate'],
true);
1633 if (is_numeric($expenseindoc[
'total_ttc'] ??
null)) {
1634 $tmpvalue[] = $langs->transnoentitiesnoconv(
"AmountTTC").
': '.
price((
float) $expenseindoc[
'total_ttc']);
1636 if (!empty($expenseindoc[
'currency_code'])) {
1637 $tmpvalue[] = $langs->transnoentitiesnoconv(
"Currency").
': '.dolPrintLabel($expenseindoc[
'currency_code']);
1639 $s = implode(
', ', $tmpvalue);
1641 print
'<span class="warning">'.$langs->trans(
"NoDataRelatedTo").
'</span>';
1648 if ($expenseuserid > 0 && $dateexpense) {
1649 $sql =
"SELECT rowid FROM ".$db->prefix().
"expensereport";
1650 $sql .=
" WHERE fk_user_author = ".((int) $expenseuserid);
1652 $sql .=
" AND date_debut <= '".$db->escape(
dol_print_date($dateexpense,
'dayrfc')).
"' AND date_fin >= '".$db->escape(
dol_print_date($dateexpense,
'dayrfc')).
"'";
1653 $sql .=
" AND entity IN (".getEntity(
'expensereport').
")";
1654 $sql .=
" ORDER BY rowid DESC";
1655 $sql .= $db->plimit(1);
1656 $resql = $db->query($sql);
1657 if ($resql && ($obj = $db->fetch_object($resql))) {
1658 $tmpexpensereport->fetch($obj->rowid);
1661 if ($tmpexpensereport->id > 0) {
1662 print $langs->trans(
"ExpenseWillBeAddedToDraftExpenseReport").
' '.$tmpexpensereport->getNomUrl(1).
'<br>';
1664 print $langs->trans(
"NewExpenseReportWillBeCreated").
'<br>';
1667 print $langs->trans(
"Type").
' ';
1668 include_once DOL_DOCUMENT_ROOT.
'/core/class/html.formexpensereport.class.php';
1670 print $formexpensereport->selectTypeExpenseReport($feetypeid > 0 ? $feetypeid :
'',
'feetypeid', 1);
1672 print $langs->trans(
"Date").
' ';
1673 print $form->selectDate($dateexpense,
'date', 0, 0, 1,
'summary-result', 1, 0);
1675 print $langs->trans(
"Description").
' ';
1676 print
'<input type="text" class="minwidth300" name="comments" id="comments" value="'.dolPrintHTMLForAttribute($comments).
'"><br>';
1677 print $langs->trans(
"VATRate").
' ';
1678 print
'<input type="text" class="width50 right" name="vat_rate" id="vat_rate" value="'.dolPrintHTMLForAttribute((
string) $vat_rate).
'">%<br>';
1679 print $langs->trans(
"AmountTTC").
' ';
1680 print
'<input type="text" class="width100 right" name="amount_ttc" id="amount_ttc" value="'.dolPrintHTMLForAttribute((
string) $amount_ttc).
'">';
1686 print
'<br><br><center><input type="submit" name="submit" class="button" value="'.$langs->trans(
"Create").
'"></center>';
1693 print
'<div id="divpreview">';
1697 if ($filetopreview &&
dol_is_file($upload_dir.
'/'.$filetopreview)) {
1699 $urltopreview = $_SERVER[
"PHP_SELF"].
'?action=displayfile&originalfilename='.urlencode($filetopreview);
1701 if ($mimetopreview ==
'application/pdf' && !empty(
$conf->dol_use_jmobile)) {
1703 $fileimagetopreview = $filetopreview.
'_preview.png';
1709 $urlimagetopreview = $_SERVER[
"PHP_SELF"].
'?action=displayfile&originalfilename='.urlencode($fileimagetopreview);
1710 print
'<div class="center">';
1711 print
'<img src="'.dolPrintHTMLForAttributeUrl($urlimagetopreview).
'" alt="'.dolPrintHTMLForAttribute($langs->transnoentitiesnoconv(
"Preview")).
'" style="max-width: 100%;">';
1714 } elseif ($mimetopreview ==
'application/pdf') {
1715 print
'<div class="center">';
1716 print
'<iframe src="'.dolPrintHTMLForAttributeUrl($urltopreview).
'" title="'.dolPrintHTMLForAttribute($langs->transnoentitiesnoconv(
"Preview")).
'" style="width: 100%; height: 800px; border: none;"></iframe>';
1718 } elseif (preg_match(
'/^image\/(png|jpeg|gif|webp|bmp)$/', $mimetopreview)) {
1719 print
'<div class="center">';
1720 print
'<img src="'.dolPrintHTMLForAttributeUrl($urltopreview).
'" alt="'.dolPrintHTMLForAttribute($langs->transnoentitiesnoconv(
"Preview")).
'" style="max-width: 100%;">';
1726 print
'<input type="hidden" name="jsonstring" value="'.base64_encode($jsonstring).
'">';
1731} elseif ($action ==
'objectcreated' && is_object($createdobject)) {
1734 print
'<div class="neutral">';
1736 if ($createdobject instanceof
Salary) {
1737 print $langs->trans(
"SalaryCreatedFromFile").
' ';
1739 print $langs->trans(
"SocialContributionCreatedFromFile").
' ';
1741 print $langs->trans(
"ExpenseAddedFromFile").
' ';
1742 } elseif ($attachtoexistinginvoice) {
1743 print $langs->trans(
"FileAttachedToExistingInvoice").
' ';
1745 print $langs->trans(
"DraftInvoiceCreatedFromFile").
' ';
1747 print $createdobject->getNomUrl(1);
1755 print
"<!-- Begin UploadForm -->\n";
1756 print
'<form id="uploadform" enctype="multipart/form-data" method="POST" action="'.dolBuildUrl($_SERVER[
"PHP_SELF"]).
'">';
1757 print
'<input type="hidden" name="token" value="'.newToken().
'">';
1758 print
'<input type="hidden" name="action" value="uploadfile">';
1759 print
'<input type="hidden" name="sendit" value="1">';
1760 print
'<input type="hidden" name="modulepart" id="modulepart" value="">';
1761 print
'<input type="hidden" name="overwritefile" value="1">';
1763 print
'<div class="center"><div class="center" style="padding: 10px;">';
1764 print
'<style>.menu_titre { padding-top: 7px; }</style>';
1765 print
'<div id="blockupload" class="center">'.
"\n";
1770 $accept =
'.pdf,image/*';
1776 $max = $maxfilesizearray[
'max'];
1777 $maxmin = $maxfilesizearray[
'maxmin'];
1778 $maxphptoshow = $maxfilesizearray[
'maxphptoshow'];
1779 $maxphptoshowparam = $maxfilesizearray[
'maxphptoshowparam'];
1782 $out .=
'<input type="hidden" name="MAX_FILE_SIZE" value="'.($maxmin * 1024).
'">';
1784 $out .=
'<input class="hideobject" type="file" id="fileInput" value=""';
1786 $out .= ((
getDolGlobalString(
'MAIN_DISABLE_MULTIPLE_FILEUPLOAD') || $disablemulti) ?
' name="userfile"' :
' name="userfile[]" multiple');
1790 $out .= (!empty($accept) ?
' accept="'.$accept.
'"' :
' accept=""');
1792 $out .= (!empty($capture) ?
' capture="capture"' :
'');
1799 $(document).ready(function() {
1800 jQuery('#supplierinvoice:not(.disableautoopen)').on('click', function(event) {
1801 console.log('Click on link supplierinvoice to open input file');
1803 if (!event.target.closest('.disableautoopen')) {
1804 $('#modulepart').val('invoice_supplier');
1805 $('#fileInput').click();
1809 jQuery('#userexpensereport:not(.disableautoopen)').on('click', function(event) {
1810 console.log('Click on link userexpensereport to open input file');
1812 if (!event.target.closest('.disableautoopen')) {
1813 $('#modulepart').val('expensereport');
1814 $('#fileInput').click();
1818 jQuery('#userpayroll:not(.disableautoopen)').on('click', function(event) {
1819 console.log('Click on link userpayroll to open input file');
1821 if (!event.target.closest('.disableautoopen')) {
1822 $('#modulepart').val('salaries');
1823 $('#fileInput').click();
1827 jQuery('#socialcontribution:not(.disableautoopen)').on('click', function(event) {
1828 console.log('Click on link socialcontribution to open input file');
1830 if (!event.target.closest('.disableautoopen')) {
1831 $('#modulepart').val('chargesociales');
1832 $('#fileInput').click();
1836 jQuery('#fileInput').on('change', function(event) {
1838 console.log('A file was selected, we submit the form');
1839 $('#uploadform').submit();
1842 // Drag and drop of a file on an upload zone. A counter is used because dragenter/dragleave are also fired by child elements.
1843 var modulepartforzone = {'supplierinvoice': 'invoice_supplier', 'userexpensereport': 'expensereport', 'userpayroll': 'salaries', 'socialcontribution': 'chargesociales'};
1844 jQuery('.flex-item-uploadfile').each(function() {
1846 var dragcounter = 0;
1847 zone.on('dragenter', function(ev) {
1848 var dataTypes = ev.originalEvent.dataTransfer.types;
1849 if (!dataTypes || $.inArray('Files', dataTypes) === -1) {
1852 ev.preventDefault();
1854 zone.addClass('highlightDragDropArea');
1856 zone.on('dragover', function(ev) {
1857 ev.preventDefault();
1859 zone.on('dragleave', function(ev) {
1861 if (dragcounter <= 0) {
1863 zone.removeClass('highlightDragDropArea');
1866 zone.on('drop', function(ev) {
1867 ev.preventDefault();
1869 zone.removeClass('highlightDragDropArea');
1870 var files = ev.originalEvent.dataTransfer.files;
1871 if (!files || !files.length || !modulepartforzone[zone.attr('id')]) {
1874 console.log('A file was dropped on '+zone.attr('id')+', we submit the form');
1875 var dt = new DataTransfer();
1876 dt.items.add(files[0]);
1877 $('#fileInput')[0].files = dt.files;
1878 $('#modulepart').val(modulepartforzone[zone.attr('id')]);
1879 $('#uploadform').submit();
1885 print
'</div>'.
"\n";
1886 print
'</div></div>';
1889 print
"\n<!-- End UploadForm -->\n";
$propal type
'integer', 'integer:ObjectClass:PathToClass[:AddCreateButtonOrNot[:Filter[:Sortfield]]]',...
getListOfAIServices()
Get list of available ai services.
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class for managing the social charges.
Class to manage ECM files.
Class to manage Trips and Expenses.
const STATUS_DRAFT
Draft status.
Class to manage suppliers invoices.
const TYPE_STANDARD
Standard invoice.
Class to manage predefined suppliers products.
Class to manage products or services.
Class to manage salary payments.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
if(! $sortfield) if(! $sortorder) $module
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
dol_move($srcfile, $destfile, $newmask='0', $overwriteifexists=1, $testvirus=0, $indexdatabase=1, $moreinfo=array(), $entity=null)
Move a file into another name.
dol_filemtime($pathoffile)
Return time of a file.
dol_filesize($pathoffile)
Return size of a file.
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_convert_file($fileinput, $ext='png', $fileoutput='', $page='')
Convert a PDF file into another image format.
dol_is_file($pathoffile)
Return if path is a file.
dol_now($mode='gmt')
Return date for now.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='', $useCache=true)
Return an id or code from a code or id.
vatrate($rate, $addpercent=false, $info_bits=0, $usestarfornpr=0, $html=0)
Return a string with VAT rate label formatted for view output Used into pdf and HTML pages.
price2num($amount, $rounding='', $option=0, $currencycode='')
Function that return a number with universal decimal format (decimal separator is '.
dol_mimetype($file, $default='application/octet-stream', $mode=0)
Return MIME type of a file from its name with extension.
dolBuildUrl($url, $params=[], $addtoken=false, $anchor='')
Return path of url.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1, $includequotes=0, $allowdash=0)
Clean a string to use it as a file name.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
getElementProperties($elementType)
Get an array with properties of an element.
dol_escape_js($stringtoescape, $mode=0, $noescapebackslashn=0)
Returns text escaped for inclusion into JavaScript code.
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
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.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
readfileLowMemory($fullpath_original_file_osencoded, $method=-1)
Return a file on output using a low memory.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
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).
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '...' if string larger than length.
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_default_tva(Societe $thirdparty_seller, Societe $thirdparty_buyer, $idprod=0, $idprodfournprice=0)
Function that return vat rate of a product line (according to seller, buyer and product vat rate) VAT...
get_localtax($vatrate, $local, $thirdparty_buyer=null, $thirdparty_seller=null, $vatnpr=0)
Return localtax rate for a particular VAT rate, when selling a product with vat $vatrate,...
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.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_getdate($timestamp, $fast=false, $forcetimezone='')
Return an array with locale date info.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
if(!defined( 'NOREQUIREMENU')) if(!empty(GETPOST('seteventmessages', 'alpha'))) if(!function_exists("llxHeader")) top_httphead($contenttype='text/html', $forcenocache=0)
Show HTTP header.
$conf db name
Only used if Module[ID]Name translation string is not found.
httponly_accessforbidden($message='1', $http_response_code=403, $stringalreadysanitized=0)
Show a message to say access is forbidden and stop program.
getMaxFileSizeArray()
Return the max allowed for file upload.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
encode($string)
Escape a text value for a vCard 4.0 (RFC 6350 section 3.4): backslash, semicolon, comma and line brea...