233 if ($this->element ===
'facture') {
234 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
237 if (
$object->fetch($this->fk_object) > 0) {
243 if ($this->element ===
'invoice_supplier') {
244 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
247 if (
$object->fetch($this->fk_object) > 0) {
252 } elseif ($this->element ===
'payment') {
253 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
256 if (
$object->fetch($this->fk_object) > 0) {
261 } elseif ($this->element ===
'payment_supplier') {
262 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
265 if (
$object->fetch($this->fk_object) > 0) {
270 } elseif ($this->element ===
'payment_donation') {
271 require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
274 if (
$object->fetch($this->fk_object) > 0) {
279 } elseif ($this->element ===
'payment_various') {
280 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
283 if (
$object->fetch($this->fk_object) > 0) {
288 } elseif ($this->element ===
'don' || $this->element ===
'donation') {
289 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
292 if (
$object->fetch($this->fk_object) > 0) {
297 } elseif ($this->element ===
'subscription') {
298 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
301 if (
$object->fetch($this->fk_object) > 0) {
306 } elseif ($this->element ===
'cashcontrol') {
307 require_once DOL_DOCUMENT_ROOT.
'/compta/cashcontrol/class/cashcontrol.class.php';
310 if (
$object->fetch($this->fk_object) > 0) {
315 } elseif ($this->element ===
'stockmouvement') {
316 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
319 if (
$object->fetch($this->fk_object) > 0) {
324 } elseif ($this->element ===
'project') {
325 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
328 if (
$object->fetch($this->fk_object) > 0) {
333 } elseif ($this->action ==
'MODULE_SET') {
334 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogEnabled").
'</i>';
335 } elseif ($this->action ==
'MODULE_RESET') {
336 if ($this->signature ==
'0000000000') {
337 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabled").
'</i>';
339 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabledBis").
'</i>';
343 return '<i class="opacitymedium">'.$langs->trans(
'ImpossibleToReloadObject', $this->element, $this->fk_object).
'</i>';
383 global $langs, $user, $mysoc;
385 if (is_object($fuser)) {
392 $this->action = $action;
394 $this->amounts = $amounts;
396 if (
$object->element ==
'payment' ||
$object->element ==
'payment_supplier') {
398 } elseif (
$object->element ==
'payment_salary') {
399 $this->date_object =
$object->datev;
400 } elseif (
$object->element ==
'payment_donation' ||
$object->element ==
'payment_various') {
402 } elseif (
$object->element ==
'subscription') {
403 $this->date_object =
$object->dateh;
404 } elseif (
$object->element ==
'cashcontrol') {
405 $this->date_object =
$object->date_creation;
406 } elseif (property_exists(
$object,
'date')) {
408 $this->date_object =
$object->date;
409 } elseif (property_exists(
$object,
'datem')) {
411 $this->date_object =
$object->datem;
417 $this->element =
$object->element;
419 $this->fk_object =
$object->id;
423 $this->object_data =
new stdClass();
425 $arrayoffieldstoexclude = array(
426 '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',
427 'table_element_line',
'ismultientitymanaged',
'isextrafieldmanaged',
436 'fk_delivery_address',
438 'restrictiononfksoc',
442 if ($this->element ==
'cashcontrol') {
443 $arrayoffieldstoexclude = array_merge($arrayoffieldstoexclude, array(
444 'name',
'lastname',
'firstname',
'region',
'region_id',
'region_code',
'state',
'state_id',
'state_code',
'country',
'country_id',
'country_code',
445 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
446 'barcode_type',
'barcode_type_code',
'barcode_type_label',
'barcode_type_coder',
'mode_reglement_id',
'cond_reglement_id',
'mode_reglement',
'cond_reglement',
'shipping_method_id',
447 'fk_incoterms',
'label_incoterms',
'location_incoterms',
'lines'));
451 if (empty(
$object->thirdparty) && method_exists(
$object,
'fetch_thirdparty')) {
454 if (!empty(
$object->thirdparty)) {
455 $this->object_data->thirdparty =
new stdClass();
457 foreach (
$object->thirdparty as $key => $value) {
458 if (in_array($key, $arrayoffieldstoexclude)) {
461 if (!in_array($key, array(
462 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
463 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
467 if (!is_object($value) && !is_null($value) && $value !==
'') {
468 $this->object_data->thirdparty->$key = $value;
474 if (!empty($mysoc)) {
475 $this->object_data->mycompany =
new stdClass();
477 foreach ($mysoc as $key => $value) {
478 if (in_array($key, $arrayoffieldstoexclude)) {
481 if (!in_array($key, array(
482 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
483 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
487 if (!is_object($value) && !is_null($value) && $value !==
'') {
488 $this->object_data->mycompany->$key = $value;
495 $this->fk_user = $user->id;
496 $this->user_fullname = $user->getFullName($langs);
500 if ($this->element ==
'facture') {
501 foreach (
$object as $key => $value) {
502 if (in_array($key, $arrayoffieldstoexclude)) {
505 if (!in_array($key, array(
506 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'datev',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public',
'lines'
510 if ($key ==
'lines') {
512 foreach ($value as $tmpline) {
514 foreach ($tmpline as $keyline => $valueline) {
515 if (!in_array($keyline, array(
516 'ref',
'multicurrency_code',
'multicurrency_total_ht',
'multicurrency_total_tva',
'multicurrency_total_ttc',
'qty',
'product_type',
'product_label',
'vat_src_code',
'tva_tx',
'info_bits',
'localtax1_tx',
'localtax2_tx',
'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2'
521 if (empty($this->object_data->invoiceline[$lineid]) || !is_object($this->object_data->invoiceline[$lineid])) {
522 $this->object_data->invoiceline[$lineid] =
new stdClass();
525 if (!is_object($valueline) && !is_null($valueline) && $valueline !==
'') {
526 $this->object_data->invoiceline[$lineid]->$keyline = $valueline;
530 } elseif (!is_object($value) && !is_null($value) && $value !==
'') {
531 $this->object_data->$key = $value;
536 $this->object_data->ref =
$object->newref;
538 } elseif ($this->element ==
'invoice_supplier') {
539 foreach (
$object as $key => $value) {
540 if (in_array($key, $arrayoffieldstoexclude)) {
543 if (!in_array($key, array(
544 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
548 if (!is_object($value) && !is_null($value) && $value !==
'') {
549 $this->object_data->$key = $value;
554 $this->object_data->ref =
$object->newref;
556 } elseif ($this->element ==
'payment' || $this->element ==
'payment_supplier' || $this->element ==
'payment_donation' || $this->element ==
'payment_various') {
560 $this->object_data->ref =
$object->ref;
561 $this->object_data->date = $datepayment;
562 $this->object_data->type_code =
dol_getIdFromCode($this->db, $paymenttypeid,
'c_paiement',
'id',
'code');
564 if (!empty(
$object->num_payment)) {
565 $this->object_data->payment_num =
$object->num_payment;
567 if (!empty(
$object->note_private)) {
568 $this->object_data->note_private =
$object->note_private;
577 $paymentpartnumber = 0;
578 foreach (
$object->amounts as $objid => $amount) {
579 if (empty($amount)) {
583 $totalamount += $amount;
586 if ($this->element ==
'payment_supplier') {
587 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
589 } elseif ($this->element ==
'payment') {
590 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
591 $tmpobject =
new Facture($this->db);
592 } elseif ($this->element ==
'payment_donation') {
593 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
594 $tmpobject =
new Don($this->db);
595 } elseif ($this->element ==
'payment_various') {
596 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
600 if (!is_object($tmpobject)) {
604 $result = $tmpobject->fetch($objid);
607 $this->error = $tmpobject->error;
608 $this->errors = $tmpobject->errors;
609 dol_syslog(
"Failed to fetch object with id ".$objid, LOG_ERR);
614 $paymentpart->amount = $amount;
616 if (!in_array($this->element, array(
'payment_donation',
'payment_various'))) {
617 $result = $tmpobject->fetch_thirdparty();
619 $this->error =
'Failed to fetch thirdparty for object with id '.$tmpobject->id;
620 $this->errors[] = $this->error;
621 dol_syslog(
"Failed to fetch thirdparty for object with id ".$tmpobject->id, LOG_ERR);
623 } elseif ($result < 0) {
624 $this->error = $tmpobject->error;
625 $this->errors = $tmpobject->errors;
629 $paymentpart->thirdparty =
new stdClass();
630 foreach ($tmpobject->thirdparty as $key => $value) {
631 if (in_array($key, $arrayoffieldstoexclude)) {
634 if (!in_array($key, array(
635 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
636 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
640 if (!is_object($value) && !is_null($value) && $value !==
'') {
641 $paymentpart->thirdparty->$key = $value;
647 if ($this->element ==
'payment_donation') {
648 $paymentpart->donation =
new stdClass();
650 $paymentpart->invoice =
new stdClass();
653 if ($this->element !=
'payment_various') {
654 foreach ($tmpobject as $key => $value) {
655 if (in_array($key, $arrayoffieldstoexclude)) {
658 if (!in_array($key, array(
659 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
663 if (!is_object($value) && !is_null($value) && $value !==
'') {
664 if ($this->element ==
'payment_donation') {
665 $paymentpart->donation->$key = $value;
666 } elseif ($this->element ==
'payment_various') {
667 $paymentpart->various->$key = $value;
669 $paymentpart->invoice->$key = $value;
674 $paymentpartnumber++;
675 $this->object_data->payment_part[$paymentpartnumber] = $paymentpart;
678 } elseif (!empty(
$object->amount)) {
679 $totalamount =
$object->amount;
682 $this->object_data->amount = $totalamount;
685 $this->object_data->ref =
$object->newref;
687 } elseif ($this->element ==
'payment_salary') {
688 $this->object_data->amounts = array(
$object->amount);
691 $this->object_data->ref =
$object->newref;
693 } elseif ($this->element ==
'subscription') {
694 foreach (
$object as $key => $value) {
695 if (in_array($key, $arrayoffieldstoexclude)) {
698 if (!in_array($key, array(
699 'id',
'datec',
'dateh',
'datef',
'fk_adherent',
'amount',
'import_key',
'statut',
'note'
703 if (!is_object($value) && !is_null($value) && $value !==
'') {
704 $this->object_data->$key = $value;
709 $this->object_data->ref =
$object->newref;
711 } elseif ($this->element ==
'stockmouvement') {
712 foreach (
$object as $key => $value) {
713 if (in_array($key, $arrayoffieldstoexclude)) {
716 if (!is_object($value) && !is_null($value) && $value !==
'') {
717 $this->object_data->$key = $value;
722 foreach (
$object as $key => $value) {
723 if (in_array($key, $arrayoffieldstoexclude)) {
726 if (!is_object($value) && !is_null($value) && $value !==
'') {
727 $this->object_data->$key = $value;
732 $this->object_data->ref =
$object->newref;
738 $this->object_data = json_decode(json_encode($this->object_data, JSON_FORCE_OBJECT),
false);
754 $this->error =
'BadParameter';
758 $sql =
"SELECT b.rowid, b.date_creation, b.signature, b.signature_line, b.amounts, b.action, b.element, b.fk_object, b.entity,";
759 $sql .=
" b.certified, b.tms, b.fk_user, b.user_fullname, b.date_object, b.ref_object, b.object_data, b.object_version";
760 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog as b";
762 $sql .=
" WHERE b.rowid = ".((int) $id);
765 $resql = $this->db->query($sql);
767 $obj = $this->db->fetch_object($resql);
769 $this->
id = $obj->rowid;
770 $this->entity = $obj->entity;
772 $this->date_creation = $this->db->jdate($obj->date_creation);
773 $this->date_modification = $this->db->jdate($obj->tms);
775 $this->amounts = (float) $obj->amounts;
776 $this->action = $obj->action;
777 $this->element = $obj->element;
779 $this->fk_object = $obj->fk_object;
780 $this->date_object = $this->db->jdate($obj->date_object);
781 $this->ref_object = $obj->ref_object;
783 $this->fk_user = $obj->fk_user;
784 $this->user_fullname = $obj->user_fullname;
787 $this->object_version = $obj->object_version;
789 $this->signature = $obj->signature;
790 $this->signature_line = $obj->signature_line;
791 $this->certified = ($obj->certified == 1);
795 $langs->load(
"blockedlog");
796 $this->error = $langs->trans(
"RecordNotFound");
800 $this->error = $this->db->error();
868 public function create($user, $forcesignature =
'')
870 global $conf, $langs, $hookmanager;
872 $langs->load(
'blockedlog');
877 $this->amounts = (float) $this->amounts;
879 dol_syslog(get_class($this).
'::create action='.$this->action.
' fk_user='.$this->fk_user.
' user_fullname='.$this->user_fullname, LOG_DEBUG);
882 if (!isset($this->amounts)) {
883 $this->error = $langs->trans(
"BlockLogNeedAmountsValue");
888 if (empty($this->element)) {
889 $this->error = $langs->trans(
"BlockLogNeedElement");
894 if (empty($this->action)) {
895 $this->error = $langs->trans(
"BadParameterWhenCallingCreateOfBlockedLog");
899 if (empty($this->fk_user)) {
900 $this->user_fullname =
'(Anonymous)';
903 $this->date_creation =
dol_now();
905 $this->object_version = ((float) DOL_VERSION);
914 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
916 $this->signature_line =
dol_hash($keyforsignature,
'5');
917 $this->signature =
dol_hash($previoushash.$keyforsignature,
'5');
918 if ($forcesignature) {
919 $this->signature = $forcesignature;
923 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog (";
924 $sql .=
" date_creation,";
927 $sql .=
" signature,";
928 $sql .=
" signature_line,";
930 $sql .=
" fk_object,";
931 $sql .=
" date_object,";
932 $sql .=
" ref_object,";
933 $sql .=
" object_data,";
934 $sql .=
" object_version,";
935 $sql .=
" certified,";
937 $sql .=
" user_fullname,";
939 $sql .=
") VALUES (";
940 $sql .=
"'".$this->db->idate($this->date_creation).
"',";
941 $sql .=
"'".$this->db->escape($this->action).
"',";
942 $sql .= $this->amounts.
",";
943 $sql .=
"'".$this->db->escape($this->signature).
"',";
944 $sql .=
"'".$this->db->escape($this->signature_line).
"',";
945 $sql .=
"'".$this->db->escape($this->element).
"',";
946 $sql .= $this->fk_object.
",";
947 $sql .=
"'".$this->db->idate($this->date_object).
"',";
948 $sql .=
"'".$this->db->escape($this->ref_object).
"',";
950 $sql .=
"'".$this->db->escape($this->object_version).
"',";
952 $sql .= $this->fk_user.
",";
953 $sql .=
"'".$this->db->escape($this->user_fullname).
"',";
954 $sql .= ($this->entity ? $this->entity : $conf->entity);
965 $res = $this->db->query($sql);
967 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog");
976 $this->db->rollback();
980 $this->error = $this->db->error();
981 $this->db->rollback();