232 if ($this->element ===
'facture') {
233 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
235 $object =
new Facture($this->db);
236 if ($object->fetch($this->fk_object) > 0) {
237 return $object->getNomUrl(1);
242 if ($this->element ===
'invoice_supplier') {
243 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
246 if ($object->fetch($this->fk_object) > 0) {
247 return $object->getNomUrl(1);
251 } elseif ($this->element ===
'payment') {
252 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
255 if ($object->fetch($this->fk_object) > 0) {
256 return $object->getNomUrl(1);
260 } elseif ($this->element ===
'payment_supplier') {
261 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
264 if ($object->fetch($this->fk_object) > 0) {
265 return $object->getNomUrl(1);
269 } elseif ($this->element ===
'payment_donation') {
270 require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
273 if ($object->fetch($this->fk_object) > 0) {
274 return $object->getNomUrl(1);
278 } elseif ($this->element ===
'payment_various') {
279 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
282 if ($object->fetch($this->fk_object) > 0) {
283 return $object->getNomUrl(1);
287 } elseif ($this->element ===
'don' || $this->element ===
'donation') {
288 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
290 $object =
new Don($this->db);
291 if ($object->fetch($this->fk_object) > 0) {
292 return $object->getNomUrl(1);
296 } elseif ($this->element ===
'subscription') {
297 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
300 if ($object->fetch($this->fk_object) > 0) {
301 return $object->getNomUrl(1);
305 } elseif ($this->element ===
'cashcontrol') {
306 require_once DOL_DOCUMENT_ROOT.
'/compta/cashcontrol/class/cashcontrol.class.php';
309 if ($object->fetch($this->fk_object) > 0) {
310 return $object->getNomUrl(1);
314 } elseif ($this->element ===
'stockmouvement') {
315 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
318 if ($object->fetch($this->fk_object) > 0) {
319 return $object->getNomUrl(1);
323 } elseif ($this->element ===
'project') {
324 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
326 $object =
new Project($this->db);
327 if ($object->fetch($this->fk_object) > 0) {
328 return $object->getNomUrl(1);
332 } elseif ($this->action ==
'MODULE_SET') {
333 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogEnabled").
'</i>';
334 } elseif ($this->action ==
'MODULE_RESET') {
335 if ($this->signature ==
'0000000000') {
336 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabled").
'</i>';
338 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabledBis").
'</i>';
342 return '<i class="opacitymedium">'.$langs->trans(
'ImpossibleToReloadObject', $this->element, $this->fk_object).
'</i>';
382 global $langs, $user, $mysoc;
384 if (is_object($fuser)) {
391 $this->action = $action;
393 $this->amounts = $amounts;
395 if ($object->element ==
'payment' || $object->element ==
'payment_supplier') {
396 $this->date_object = empty($object->datepaye) ? $object->date : $object->datepaye;
397 } elseif ($object->element ==
'payment_salary') {
398 $this->date_object = $object->datev;
399 } elseif ($object->element ==
'payment_donation' || $object->element ==
'payment_various') {
400 $this->date_object = empty($object->datepaid) ? $object->datep : $object->datepaid;
401 } elseif ($object->element ==
'subscription') {
402 $this->date_object = $object->dateh;
403 } elseif ($object->element ==
'cashcontrol') {
404 $this->date_object = $object->date_creation;
405 } elseif (property_exists($object,
'date')) {
407 $this->date_object = $object->date;
408 } elseif (property_exists($object,
'datem')) {
410 $this->date_object = $object->datem;
414 $this->ref_object = ((!empty($object->newref)) ? $object->newref : $object->ref);
416 $this->element = $object->element;
418 $this->fk_object = $object->id;
422 $this->object_data =
new stdClass();
424 $arrayoffieldstoexclude = array(
425 'table_element',
'fields',
'ref_previous',
'ref_next',
'origin',
'origin_id',
'oldcopy',
'picto',
'error',
'errors',
'model_pdf',
'modelpdf',
'last_main_doc',
'civility_id',
'contact',
'contact_id',
426 'table_element_line',
'ismultientitymanaged',
'isextrafieldmanaged',
435 'fk_delivery_address',
437 'restrictiononfksoc',
441 if ($this->element ==
'cashcontrol') {
442 $arrayoffieldstoexclude = array_merge($arrayoffieldstoexclude, array(
443 'name',
'lastname',
'firstname',
'region',
'region_id',
'region_code',
'state',
'state_id',
'state_code',
'country',
'country_id',
'country_code',
444 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
445 'barcode_type',
'barcode_type_code',
'barcode_type_label',
'barcode_type_coder',
'mode_reglement_id',
'cond_reglement_id',
'mode_reglement',
'cond_reglement',
'shipping_method_id',
446 'fk_incoterms',
'label_incoterms',
'location_incoterms',
'lines'));
450 if (empty($object->thirdparty) && method_exists($object,
'fetch_thirdparty')) {
451 $object->fetch_thirdparty();
453 if (!empty($object->thirdparty)) {
454 $this->object_data->thirdparty =
new stdClass();
456 foreach ($object->thirdparty as $key => $value) {
457 if (in_array($key, $arrayoffieldstoexclude)) {
460 if (!in_array($key, array(
461 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
462 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
466 if (!is_object($value) && !is_null($value) && $value !==
'') {
467 $this->object_data->thirdparty->$key = $value;
473 if (!empty($mysoc)) {
474 $this->object_data->mycompany =
new stdClass();
476 foreach ($mysoc as $key => $value) {
477 if (in_array($key, $arrayoffieldstoexclude)) {
480 if (!in_array($key, array(
481 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
482 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
486 if (!is_object($value) && !is_null($value) && $value !==
'') {
487 $this->object_data->mycompany->$key = $value;
494 $this->fk_user = $user->id;
495 $this->user_fullname = $user->getFullName($langs);
499 if ($this->element ==
'facture') {
500 foreach ($object as $key => $value) {
501 if (in_array($key, $arrayoffieldstoexclude)) {
504 if (!in_array($key, array(
505 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'datev',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public',
'lines'
509 if ($key ==
'lines') {
511 foreach ($value as $tmpline) {
513 foreach ($tmpline as $keyline => $valueline) {
514 if (!in_array($keyline, array(
515 'ref',
'multicurrency_code',
'multicurrency_total_ht',
'multicurrency_total_tva',
'multicurrency_total_ttc',
'qty',
'product_type',
'vat_src_code',
'tva_tx',
'info_bits',
'localtax1_tx',
'localtax2_tx',
'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2'
520 if (empty($this->object_data->invoiceline[$lineid]) || !is_object($this->object_data->invoiceline[$lineid])) {
521 $this->object_data->invoiceline[$lineid] =
new stdClass();
524 if (!is_object($valueline) && !is_null($valueline) && $valueline !==
'') {
525 $this->object_data->invoiceline[$lineid]->$keyline = $valueline;
529 } elseif (!is_object($value) && !is_null($value) && $value !==
'') {
530 $this->object_data->$key = $value;
534 if (!empty($object->newref)) {
535 $this->object_data->ref = $object->newref;
537 } elseif ($this->element ==
'invoice_supplier') {
538 foreach ($object as $key => $value) {
539 if (in_array($key, $arrayoffieldstoexclude)) {
542 if (!in_array($key, array(
543 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
547 if (!is_object($value) && !is_null($value) && $value !==
'') {
548 $this->object_data->$key = $value;
552 if (!empty($object->newref)) {
553 $this->object_data->ref = $object->newref;
555 } elseif ($this->element ==
'payment' || $this->element ==
'payment_supplier' || $this->element ==
'payment_donation' || $this->element ==
'payment_various') {
556 $datepayment = $object->datepaye ? $object->datepaye : ($object->datepaid ? $object->datepaid : $object->datep);
557 $paymenttypeid = $object->paiementid ? $object->paiementid : ($object->paymenttype ? $object->paymenttype : $object->type_payment);
559 $this->object_data->ref = $object->ref;
560 $this->object_data->date = $datepayment;
561 $this->object_data->type_code =
dol_getIdFromCode($this->db, $paymenttypeid,
'c_paiement',
'id',
'code');
563 if (!empty($object->num_payment)) {
564 $this->object_data->payment_num = $object->num_payment;
566 if (!empty($object->note_private)) {
567 $this->object_data->note_private = $object->note_private;
575 if (is_array($object->amounts) && !empty($object->amounts)) {
576 $paymentpartnumber = 0;
577 foreach ($object->amounts as $objid => $amount) {
578 if (empty($amount)) {
582 $totalamount += $amount;
585 if ($this->element ==
'payment_supplier') {
586 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
588 } elseif ($this->element ==
'payment') {
589 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
590 $tmpobject =
new Facture($this->db);
591 } elseif ($this->element ==
'payment_donation') {
592 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
593 $tmpobject =
new Don($this->db);
594 } elseif ($this->element ==
'payment_various') {
595 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
599 if (!is_object($tmpobject)) {
603 $result = $tmpobject->fetch($objid);
606 $this->error = $tmpobject->error;
607 $this->errors = $tmpobject->errors;
608 dol_syslog(
"Failed to fetch object with id ".$objid, LOG_ERR);
613 $paymentpart->amount = $amount;
615 if (!in_array($this->element, array(
'payment_donation',
'payment_various'))) {
616 $result = $tmpobject->fetch_thirdparty();
618 $this->error =
'Failed to fetch thirdparty for object with id '.$tmpobject->id;
619 $this->errors[] = $this->error;
620 dol_syslog(
"Failed to fetch thirdparty for object with id ".$tmpobject->id, LOG_ERR);
622 } elseif ($result < 0) {
623 $this->error = $tmpobject->error;
624 $this->errors = $tmpobject->errors;
628 $paymentpart->thirdparty =
new stdClass();
629 foreach ($tmpobject->thirdparty as $key => $value) {
630 if (in_array($key, $arrayoffieldstoexclude)) {
633 if (!in_array($key, array(
634 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
635 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
639 if (!is_object($value) && !is_null($value) && $value !==
'') {
640 $paymentpart->thirdparty->$key = $value;
646 if ($this->element ==
'payment_donation') {
647 $paymentpart->donation =
new stdClass();
649 $paymentpart->invoice =
new stdClass();
652 if ($this->element !=
'payment_various') {
653 foreach ($tmpobject as $key => $value) {
654 if (in_array($key, $arrayoffieldstoexclude)) {
657 if (!in_array($key, array(
658 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
662 if (!is_object($value) && !is_null($value) && $value !==
'') {
663 if ($this->element ==
'payment_donation') {
664 $paymentpart->donation->$key = $value;
665 } elseif ($this->element ==
'payment_various') {
666 $paymentpart->various->$key = $value;
668 $paymentpart->invoice->$key = $value;
673 $paymentpartnumber++;
674 $this->object_data->payment_part[$paymentpartnumber] = $paymentpart;
677 } elseif (!empty($object->amount)) {
678 $totalamount = $object->amount;
681 $this->object_data->amount = $totalamount;
683 if (!empty($object->newref)) {
684 $this->object_data->ref = $object->newref;
686 } elseif ($this->element ==
'payment_salary') {
687 $this->object_data->amounts = array($object->amount);
689 if (!empty($object->newref)) {
690 $this->object_data->ref = $object->newref;
692 } elseif ($this->element ==
'subscription') {
693 foreach ($object as $key => $value) {
694 if (in_array($key, $arrayoffieldstoexclude)) {
697 if (!in_array($key, array(
698 'id',
'datec',
'dateh',
'datef',
'fk_adherent',
'amount',
'import_key',
'statut',
'note'
702 if (!is_object($value) && !is_null($value) && $value !==
'') {
703 $this->object_data->$key = $value;
707 if (!empty($object->newref)) {
708 $this->object_data->ref = $object->newref;
710 } elseif ($this->element ==
'stockmouvement') {
711 foreach ($object as $key => $value) {
712 if (in_array($key, $arrayoffieldstoexclude)) {
715 if (!is_object($value) && !is_null($value) && $value !==
'') {
716 $this->object_data->$key = $value;
721 foreach ($object as $key => $value) {
722 if (in_array($key, $arrayoffieldstoexclude)) {
725 if (!is_object($value) && !is_null($value) && $value !==
'') {
726 $this->object_data->$key = $value;
730 if (!empty($object->newref)) {
731 $this->object_data->ref = $object->newref;
737 $this->object_data = json_decode(json_encode($this->object_data, JSON_FORCE_OBJECT),
false);
867 public function create($user, $forcesignature =
'')
869 global $conf, $langs, $hookmanager;
871 $langs->load(
'blockedlog');
876 $this->amounts = (float) $this->amounts;
878 dol_syslog(get_class($this).
'::create action='.$this->action.
' fk_user='.$this->fk_user.
' user_fullname='.$this->user_fullname, LOG_DEBUG);
881 if (!isset($this->amounts)) {
882 $this->error = $langs->trans(
"BlockLogNeedAmountsValue");
887 if (empty($this->element)) {
888 $this->error = $langs->trans(
"BlockLogNeedElement");
893 if (empty($this->action)) {
894 $this->error = $langs->trans(
"BadParameterWhenCallingCreateOfBlockedLog");
898 if (empty($this->fk_user)) {
899 $this->user_fullname =
'(Anonymous)';
902 $this->date_creation =
dol_now();
904 $this->object_version = ((float) DOL_VERSION);
913 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
915 $this->signature_line =
dol_hash($keyforsignature,
'5');
916 $this->signature =
dol_hash($previoushash.$keyforsignature,
'5');
917 if ($forcesignature) {
918 $this->signature = $forcesignature;
922 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog (";
923 $sql .=
" date_creation,";
926 $sql .=
" signature,";
927 $sql .=
" signature_line,";
929 $sql .=
" fk_object,";
930 $sql .=
" date_object,";
931 $sql .=
" ref_object,";
932 $sql .=
" object_data,";
933 $sql .=
" object_version,";
934 $sql .=
" certified,";
936 $sql .=
" user_fullname,";
938 $sql .=
") VALUES (";
939 $sql .=
"'".$this->db->idate($this->date_creation).
"',";
940 $sql .=
"'".$this->db->escape($this->action).
"',";
941 $sql .= $this->amounts.
",";
942 $sql .=
"'".$this->db->escape($this->signature).
"',";
943 $sql .=
"'".$this->db->escape($this->signature_line).
"',";
944 $sql .=
"'".$this->db->escape($this->element).
"',";
945 $sql .= $this->fk_object.
",";
946 $sql .=
"'".$this->db->idate($this->date_object).
"',";
947 $sql .=
"'".$this->db->escape($this->ref_object).
"',";
949 $sql .=
"'".$this->db->escape($this->object_version).
"',";
951 $sql .= $this->fk_user.
",";
952 $sql .=
"'".$this->db->escape($this->user_fullname).
"',";
953 $sql .= ($this->entity ? $this->entity : $conf->entity);
964 $res = $this->db->query($sql);
966 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog");
975 $this->db->rollback();
979 $this->error = $this->db->error();
980 $this->db->rollback();