227 if ($this->element ===
'facture') {
228 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
230 $object =
new Facture($this->db);
231 if ($object->fetch($this->fk_object) > 0) {
232 return $object->getNomUrl(1);
237 if ($this->element ===
'invoice_supplier') {
238 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
241 if ($object->fetch($this->fk_object) > 0) {
242 return $object->getNomUrl(1);
246 } elseif ($this->element ===
'payment') {
247 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
250 if ($object->fetch($this->fk_object) > 0) {
251 return $object->getNomUrl(1);
255 } elseif ($this->element ===
'payment_supplier') {
256 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
259 if ($object->fetch($this->fk_object) > 0) {
260 return $object->getNomUrl(1);
264 } elseif ($this->element ===
'payment_donation') {
265 require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
268 if ($object->fetch($this->fk_object) > 0) {
269 return $object->getNomUrl(1);
273 } elseif ($this->element ===
'payment_various') {
274 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
277 if ($object->fetch($this->fk_object) > 0) {
278 return $object->getNomUrl(1);
282 } elseif ($this->element ===
'don' || $this->element ===
'donation') {
283 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
285 $object =
new Don($this->db);
286 if ($object->fetch($this->fk_object) > 0) {
287 return $object->getNomUrl(1);
291 } elseif ($this->element ===
'subscription') {
292 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
295 if ($object->fetch($this->fk_object) > 0) {
296 return $object->getNomUrl(1);
300 } elseif ($this->element ===
'cashcontrol') {
301 require_once DOL_DOCUMENT_ROOT.
'/compta/cashcontrol/class/cashcontrol.class.php';
304 if ($object->fetch($this->fk_object) > 0) {
305 return $object->getNomUrl(1);
309 } elseif ($this->element ===
'stockmouvement') {
310 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
313 if ($object->fetch($this->fk_object) > 0) {
314 return $object->getNomUrl(1);
318 } elseif ($this->action ==
'MODULE_SET') {
319 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogEnabled").
'</i>';
320 } elseif ($this->action ==
'MODULE_RESET') {
321 if ($this->signature ==
'0000000000') {
322 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabled").
'</i>';
324 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabledBis").
'</i>';
328 return '<i class="opacitymedium">'.$langs->trans(
'ImpossibleToReloadObject', $this->element, $this->fk_object).
'</i>';
368 global $langs, $user, $mysoc;
370 if (is_object($fuser)) {
377 $this->action = $action;
379 $this->amounts = $amounts;
381 if ($object->element ==
'payment' || $object->element ==
'payment_supplier') {
382 $this->date_object = empty($object->datepaye) ? $object->date : $object->datepaye;
383 } elseif ($object->element ==
'payment_salary') {
384 $this->date_object = $object->datev;
385 } elseif ($object->element ==
'payment_donation' || $object->element ==
'payment_various') {
386 $this->date_object = empty($object->datepaid) ? $object->datep : $object->datepaid;
387 } elseif ($object->element ==
'subscription') {
388 $this->date_object = $object->dateh;
389 } elseif ($object->element ==
'cashcontrol') {
390 $this->date_object = $object->date_creation;
391 } elseif (property_exists($object,
'date')) {
393 $this->date_object = $object->date;
394 } elseif (property_exists($object,
'datem')) {
396 $this->date_object = $object->datem;
400 $this->ref_object = ((!empty($object->newref)) ? $object->newref : $object->ref);
402 $this->element = $object->element;
404 $this->fk_object = $object->id;
408 $this->object_data =
new stdClass();
410 $arrayoffieldstoexclude = array(
411 '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',
412 'table_element_line',
'ismultientitymanaged',
'isextrafieldmanaged',
421 'fk_delivery_address',
423 'restrictiononfksoc',
427 if ($this->element ==
'cashcontrol') {
428 $arrayoffieldstoexclude = array_merge($arrayoffieldstoexclude, array(
429 'name',
'lastname',
'firstname',
'region',
'region_id',
'region_code',
'state',
'state_id',
'state_code',
'country',
'country_id',
'country_code',
430 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
431 'barcode_type',
'barcode_type_code',
'barcode_type_label',
'barcode_type_coder',
'mode_reglement_id',
'cond_reglement_id',
'mode_reglement',
'cond_reglement',
'shipping_method_id',
432 'fk_incoterms',
'label_incoterms',
'location_incoterms',
'lines'));
436 if (empty($object->thirdparty) && method_exists($object,
'fetch_thirdparty')) {
437 $object->fetch_thirdparty();
439 if (!empty($object->thirdparty)) {
440 $this->object_data->thirdparty =
new stdClass();
442 foreach ($object->thirdparty as $key => $value) {
443 if (in_array($key, $arrayoffieldstoexclude)) {
446 if (!in_array($key, array(
447 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
448 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
452 if (!is_object($value) && !is_null($value) && $value !==
'') {
453 $this->object_data->thirdparty->$key = $value;
459 if (!empty($mysoc)) {
460 $this->object_data->mycompany =
new stdClass();
462 foreach ($mysoc as $key => $value) {
463 if (in_array($key, $arrayoffieldstoexclude)) {
466 if (!in_array($key, array(
467 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
468 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
472 if (!is_object($value) && !is_null($value) && $value !==
'') {
473 $this->object_data->mycompany->$key = $value;
480 $this->fk_user = $user->id;
481 $this->user_fullname = $user->getFullName($langs);
485 if ($this->element ==
'facture') {
486 foreach ($object as $key => $value) {
487 if (in_array($key, $arrayoffieldstoexclude)) {
490 if (!in_array($key, array(
491 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'datev',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public',
'lines'
495 if ($key ==
'lines') {
497 foreach ($value as $tmpline) {
499 foreach ($tmpline as $keyline => $valueline) {
500 if (!in_array($keyline, array(
501 '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'
506 if (empty($this->object_data->invoiceline[$lineid]) || !is_object($this->object_data->invoiceline[$lineid])) {
507 $this->object_data->invoiceline[$lineid] =
new stdClass();
510 if (!is_object($valueline) && !is_null($valueline) && $valueline !==
'') {
511 $this->object_data->invoiceline[$lineid]->$keyline = $valueline;
515 } elseif (!is_object($value) && !is_null($value) && $value !==
'') {
516 $this->object_data->$key = $value;
520 if (!empty($object->newref)) {
521 $this->object_data->ref = $object->newref;
523 } elseif ($this->element ==
'invoice_supplier') {
524 foreach ($object as $key => $value) {
525 if (in_array($key, $arrayoffieldstoexclude)) {
528 if (!in_array($key, array(
529 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
533 if (!is_object($value) && !is_null($value) && $value !==
'') {
534 $this->object_data->$key = $value;
538 if (!empty($object->newref)) {
539 $this->object_data->ref = $object->newref;
541 } elseif ($this->element ==
'payment' || $this->element ==
'payment_supplier' || $this->element ==
'payment_donation' || $this->element ==
'payment_various') {
542 $datepayment = $object->datepaye ? $object->datepaye : ($object->datepaid ? $object->datepaid : $object->datep);
543 $paymenttypeid = $object->paiementid ? $object->paiementid : ($object->paymenttype ? $object->paymenttype : $object->type_payment);
545 $this->object_data->ref = $object->ref;
546 $this->object_data->date = $datepayment;
547 $this->object_data->type_code =
dol_getIdFromCode($this->db, $paymenttypeid,
'c_paiement',
'id',
'code');
549 if (!empty($object->num_payment)) {
550 $this->object_data->payment_num = $object->num_payment;
552 if (!empty($object->note_private)) {
553 $this->object_data->note_private = $object->note_private;
561 if (is_array($object->amounts) && !empty($object->amounts)) {
562 $paymentpartnumber = 0;
563 foreach ($object->amounts as $objid => $amount) {
564 if (empty($amount)) {
568 $totalamount += $amount;
571 if ($this->element ==
'payment_supplier') {
572 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
574 } elseif ($this->element ==
'payment') {
575 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
576 $tmpobject =
new Facture($this->db);
577 } elseif ($this->element ==
'payment_donation') {
578 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
579 $tmpobject =
new Don($this->db);
580 } elseif ($this->element ==
'payment_various') {
581 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
585 if (!is_object($tmpobject)) {
589 $result = $tmpobject->fetch($objid);
592 $this->error = $tmpobject->error;
593 $this->errors = $tmpobject->errors;
594 dol_syslog(
"Failed to fetch object with id ".$objid, LOG_ERR);
598 $paymentpart =
new stdClass();
599 $paymentpart->amount = $amount;
601 if (!in_array($this->element, array(
'payment_donation',
'payment_various'))) {
602 $result = $tmpobject->fetch_thirdparty();
604 $this->error =
'Failed to fetch thirdparty for object with id '.$tmpobject->id;
605 $this->errors[] = $this->error;
606 dol_syslog(
"Failed to fetch thirdparty for object with id ".$tmpobject->id, LOG_ERR);
608 } elseif ($result < 0) {
609 $this->error = $tmpobject->error;
610 $this->errors = $tmpobject->errors;
614 $paymentpart->thirdparty =
new stdClass();
615 foreach ($tmpobject->thirdparty as $key => $value) {
616 if (in_array($key, $arrayoffieldstoexclude)) {
619 if (!in_array($key, array(
620 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
621 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
625 if (!is_object($value) && !is_null($value) && $value !==
'') {
626 $paymentpart->thirdparty->$key = $value;
632 if ($this->element ==
'payment_donation') {
633 $paymentpart->donation =
new stdClass();
635 $paymentpart->invoice =
new stdClass();
638 if ($this->element !=
'payment_various') {
639 foreach ($tmpobject as $key => $value) {
640 if (in_array($key, $arrayoffieldstoexclude)) {
643 if (!in_array($key, array(
644 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
648 if (!is_object($value) && !is_null($value) && $value !==
'') {
649 if ($this->element ==
'payment_donation') {
650 $paymentpart->donation->$key = $value;
651 } elseif ($this->element ==
'payment_various') {
652 $paymentpart->various->$key = $value;
654 $paymentpart->invoice->$key = $value;
659 $paymentpartnumber++;
660 $this->object_data->payment_part[$paymentpartnumber] = $paymentpart;
663 } elseif (!empty($object->amount)) {
664 $totalamount = $object->amount;
667 $this->object_data->amount = $totalamount;
669 if (!empty($object->newref)) {
670 $this->object_data->ref = $object->newref;
672 } elseif ($this->element ==
'payment_salary') {
673 $this->object_data->amounts = array($object->amount);
675 if (!empty($object->newref)) {
676 $this->object_data->ref = $object->newref;
678 } elseif ($this->element ==
'subscription') {
679 foreach ($object as $key => $value) {
680 if (in_array($key, $arrayoffieldstoexclude)) {
683 if (!in_array($key, array(
684 'id',
'datec',
'dateh',
'datef',
'fk_adherent',
'amount',
'import_key',
'statut',
'note'
688 if (!is_object($value) && !is_null($value) && $value !==
'') {
689 $this->object_data->$key = $value;
693 if (!empty($object->newref)) {
694 $this->object_data->ref = $object->newref;
696 } elseif ($this->element ==
'stockmouvement') {
697 foreach ($object as $key => $value) {
698 if (in_array($key, $arrayoffieldstoexclude)) {
701 if (!is_object($value) && !is_null($value) && $value !==
'') {
702 $this->object_data->$key = $value;
707 foreach ($object as $key => $value) {
708 if (in_array($key, $arrayoffieldstoexclude)) {
711 if (!is_object($value) && !is_null($value) && $value !==
'') {
712 $this->object_data->$key = $value;
716 if (!empty($object->newref)) {
717 $this->object_data->ref = $object->newref;
723 $this->object_data = json_decode(json_encode($this->object_data, JSON_FORCE_OBJECT),
false);
855 public function create($user, $forcesignature =
'')
857 global $conf, $langs, $hookmanager;
859 $langs->load(
'blockedlog');
864 $this->amounts = (double) $this->amounts;
866 dol_syslog(get_class($this).
'::create action='.$this->action.
' fk_user='.$this->fk_user.
' user_fullname='.$this->user_fullname, LOG_DEBUG);
869 if (!isset($this->amounts)) {
870 $this->error = $langs->trans(
"BlockLogNeedAmountsValue");
875 if (empty($this->element)) {
876 $this->error = $langs->trans(
"BlockLogNeedElement");
881 if (empty($this->action)) {
882 $this->error = $langs->trans(
"BadParameterWhenCallingCreateOfBlockedLog");
886 if (empty($this->fk_user)) {
887 $this->user_fullname =
'(Anonymous)';
890 $this->date_creation =
dol_now();
892 $this->object_version = ((float) DOL_VERSION);
901 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
903 $this->signature_line =
dol_hash($keyforsignature,
'5');
904 $this->signature =
dol_hash($previoushash.$keyforsignature,
'5');
905 if ($forcesignature) {
906 $this->signature = $forcesignature;
910 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog (";
911 $sql .=
" date_creation,";
914 $sql .=
" signature,";
915 $sql .=
" signature_line,";
917 $sql .=
" fk_object,";
918 $sql .=
" date_object,";
919 $sql .=
" ref_object,";
920 $sql .=
" object_data,";
921 $sql .=
" object_version,";
922 $sql .=
" certified,";
924 $sql .=
" user_fullname,";
926 $sql .=
") VALUES (";
927 $sql .=
"'".$this->db->idate($this->date_creation).
"',";
928 $sql .=
"'".$this->db->escape($this->action).
"',";
929 $sql .= $this->amounts.
",";
930 $sql .=
"'".$this->db->escape($this->signature).
"',";
931 $sql .=
"'".$this->db->escape($this->signature_line).
"',";
932 $sql .=
"'".$this->db->escape($this->element).
"',";
933 $sql .= $this->fk_object.
",";
934 $sql .=
"'".$this->db->idate($this->date_object).
"',";
935 $sql .=
"'".$this->db->escape($this->ref_object).
"',";
937 $sql .=
"'".$this->db->escape($this->object_version).
"',";
939 $sql .= $this->fk_user.
",";
940 $sql .=
"'".$this->db->escape($this->user_fullname).
"',";
941 $sql .= ($this->entity ? $this->entity : $conf->entity);
952 $res = $this->db->query($sql);
954 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog");
963 $this->db->rollback();
967 $this->error = $this->db->error();
968 $this->db->rollback();