260 if ($this->element ===
'facture') {
261 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
264 if (
$object->fetch($this->fk_object) > 0) {
267 $this->error = (string) (((
int) $this->error) + 1);
270 if ($this->element ===
'invoice_supplier') {
271 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
274 if (
$object->fetch($this->fk_object) > 0) {
277 $this->error = (string) (((
int) $this->error) + 1);
279 } elseif ($this->element ===
'payment') {
280 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
283 if (
$object->fetch($this->fk_object) > 0) {
286 $this->error = (string) (((
int) $this->error) + 1);
288 } elseif ($this->element ===
'payment_supplier') {
289 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
292 if (
$object->fetch($this->fk_object) > 0) {
295 $this->error = (string) (((
int) $this->error) + 1);
297 } elseif ($this->element ===
'payment_donation') {
298 require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
301 if (
$object->fetch($this->fk_object) > 0) {
304 $this->error = (string) (((
int) $this->error) + 1);
306 } elseif ($this->element ===
'payment_various') {
307 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
310 if (
$object->fetch($this->fk_object) > 0) {
313 $this->error = (string) (((
int) $this->error) + 1);
315 } elseif ($this->element ===
'don' || $this->element ===
'donation') {
316 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
319 if (
$object->fetch($this->fk_object) > 0) {
322 $this->error = (string) (((
int) $this->error) + 1);
324 } elseif ($this->element ===
'subscription') {
325 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
328 if (
$object->fetch($this->fk_object) > 0) {
331 $this->error = (string) (((
int) $this->error) + 1);
333 } elseif ($this->element ===
'cashcontrol') {
334 require_once DOL_DOCUMENT_ROOT.
'/compta/cashcontrol/class/cashcontrol.class.php';
337 if (
$object->fetch($this->fk_object) > 0) {
340 $this->error = (string) (((
int) $this->error) + 1);
342 } elseif ($this->element ===
'stockmouvement') {
343 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
346 if (
$object->fetch($this->fk_object) > 0) {
349 $this->error = (string) (((
int) $this->error) + 1);
351 } elseif ($this->element ===
'project') {
352 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
355 if (
$object->fetch($this->fk_object) > 0) {
358 $this->error = (string) (((
int) $this->error) + 1);
360 } elseif ($this->action ==
'BLOCKEDLOG_EXPORT') {
361 return '<i class="opacitymedium">'.$langs->trans(
"logBLOCKEDLOG_EXPORT").
'</i>';
362 } elseif ($this->action ==
'MODULE_SET') {
363 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogEnabled").
'</i>';
364 } elseif ($this->action ==
'MODULE_RESET') {
365 if ($this->signature ==
'0000000000') {
366 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabled").
'</i>';
368 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabledBis").
'</i>';
372 return '<i class="opacitymedium">'.$langs->trans(
'ImpossibleToReloadObject', $this->element, $this->fk_object).
'</i>';
413 global $langs, $user, $mysoc;
415 if (is_object($fuser)) {
422 $this->action = $action;
424 $this->amounts = $amounts;
426 if (
$object->element ==
'payment' ||
$object->element ==
'payment_supplier') {
427 '@phan-var-force Paiement|PaiementFourn $object';
429 } elseif (
$object->element ==
'payment_salary') {
430 '@phan-var-force PaymentSalary $object';
431 $this->date_object =
$object->datev;
432 } elseif (
$object->element ==
'payment_donation' ||
$object->element ==
'payment_various') {
433 '@phan-var-force PaymentDonation $object';
435 } elseif (
$object->element ==
'subscription') {
436 '@phan-var-force Subscription $object';
437 $this->date_object =
$object->dateh;
438 } elseif (
$object->element ==
'cashcontrol') {
439 '@phan-var-force CashControl $object';
440 $this->date_object =
$object->date_creation;
441 } elseif (property_exists(
$object,
'date')) {
443 $this->date_object =
$object->date;
444 } elseif (property_exists(
$object,
'datem')) {
446 $this->date_object =
$object->datem;
452 $this->element =
$object->element;
454 $this->fk_object =
$object->id;
458 $this->object_data =
new stdClass();
460 $arrayoffieldstoexclude = array(
461 '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',
462 'table_element_line',
'ismultientitymanaged',
'isextrafieldmanaged',
471 'fk_delivery_address',
473 'restrictiononfksoc',
477 if ($this->element ==
'cashcontrol') {
478 $arrayoffieldstoexclude = array_merge($arrayoffieldstoexclude, array(
479 'name',
'lastname',
'firstname',
'region',
'region_id',
'region_code',
'state',
'state_id',
'state_code',
'country',
'country_id',
'country_code',
480 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
481 'barcode_type',
'barcode_type_code',
'barcode_type_label',
'barcode_type_coder',
'mode_reglement_id',
'cond_reglement_id',
'mode_reglement',
'cond_reglement',
'shipping_method_id',
482 'fk_incoterms',
'label_incoterms',
'location_incoterms',
'lines'));
486 if (empty(
$object->thirdparty) && method_exists(
$object,
'fetch_thirdparty')) {
489 if (!empty(
$object->thirdparty)) {
490 $this->object_data->thirdparty =
new stdClass();
492 foreach (
$object->thirdparty as $key => $value) {
493 if (in_array($key, $arrayoffieldstoexclude)) {
496 if (!in_array($key, array(
497 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
498 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
502 if (!is_object($value) && !is_null($value) && $value !==
'') {
503 $this->object_data->thirdparty->$key = $value;
509 if (!empty($mysoc)) {
510 $this->object_data->mycompany =
new stdClass();
512 foreach ($mysoc as $key => $value) {
513 if (in_array($key, $arrayoffieldstoexclude)) {
516 if (!in_array($key, array(
517 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
518 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
522 if (!is_object($value) && !is_null($value) && $value !==
'') {
523 $this->object_data->mycompany->$key = $value;
530 $this->fk_user = $user->id;
531 $this->user_fullname = $user->getFullName($langs);
535 if ($this->element ==
'facture') {
536 '@phan-var-force Facture $object';
537 foreach (
$object as $key => $value) {
538 if (in_array($key, $arrayoffieldstoexclude)) {
541 if (!in_array($key, array(
542 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'datev',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public',
'lines',
543 'module_source',
'pos_source'
547 if ($key ==
'lines') {
549 foreach ($value as $tmpline) {
551 foreach ($tmpline as $keyline => $valueline) {
552 if (!in_array($keyline, array(
553 'ref',
'product_type',
'product_label',
556 'vat_src_code',
'tva_tx',
'localtax1_tx',
'localtax2_tx',
557 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
558 'multicurrency_code',
'multicurrency_total_ht',
'multicurrency_total_tva',
'multicurrency_total_ttc',
559 'info_bits',
'special_code',
564 if (empty($this->object_data->invoiceline[$lineid]) || !is_object($this->object_data->invoiceline[$lineid])) {
565 $this->object_data->invoiceline[$lineid] =
new stdClass();
568 if (!is_object($valueline) && !is_null($valueline) && $valueline !==
'') {
569 $this->object_data->invoiceline[$lineid]->$keyline = $valueline;
573 } elseif (!is_object($value) && !is_null($value) && $value !==
'') {
574 $this->object_data->$key = $value;
579 $this->object_data->ref =
$object->newref;
581 } elseif ($this->element ==
'invoice_supplier') {
582 '@phan-var-force FactureFournisseur $object';
583 foreach (
$object as $key => $value) {
584 if (in_array($key, $arrayoffieldstoexclude)) {
587 if (!in_array($key, array(
588 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
592 if (!is_object($value) && !is_null($value) && $value !==
'') {
593 $this->object_data->$key = $value;
598 $this->object_data->ref =
$object->newref;
600 } elseif ($this->element ==
'payment' || $this->element ==
'payment_supplier' || $this->element ==
'payment_donation' || $this->element ==
'payment_various') {
601 '@phan-var-force Paiement|PaiementFourn|PaymentDonation|PaymentVarious $object';
605 $this->object_data->ref =
$object->ref;
606 $this->object_data->date = $datepayment;
607 $this->object_data->type_code =
dol_getIdFromCode($this->db, $paymenttypeid,
'c_paiement',
'id',
'code');
609 if (!empty(
$object->num_payment)) {
610 $this->object_data->payment_num =
$object->num_payment;
612 if (!empty(
$object->note_private)) {
613 $this->object_data->note_private =
$object->note_private;
622 $paymentpartnumber = 0;
623 foreach (
$object->amounts as $objid => $amount) {
624 if (empty($amount)) {
628 $totalamount += $amount;
631 if ($this->element ==
'payment_supplier') {
632 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
634 } elseif ($this->element ==
'payment') {
635 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
636 $tmpobject =
new Facture($this->db);
637 } elseif ($this->element ==
'payment_donation') {
638 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
639 $tmpobject =
new Don($this->db);
640 } elseif ($this->element ==
'payment_various') {
641 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
645 if (!is_object($tmpobject)) {
649 $result = $tmpobject->fetch($objid);
652 $this->error = $tmpobject->error;
653 $this->errors = $tmpobject->errors;
654 dol_syslog(
"Failed to fetch object with id ".$objid, LOG_ERR);
659 $paymentpart->amount = $amount;
661 if (!in_array($this->element, array(
'payment_donation',
'payment_various'))) {
662 $result = $tmpobject->fetch_thirdparty();
664 $this->error =
'Failed to fetch thirdparty for object with id '.$tmpobject->id;
665 $this->errors[] = $this->error;
666 dol_syslog(
"Failed to fetch thirdparty for object with id ".$tmpobject->id, LOG_ERR);
668 } elseif ($result < 0) {
669 $this->error = $tmpobject->error;
670 $this->errors = $tmpobject->errors;
674 $paymentpart->thirdparty =
new stdClass();
675 foreach ($tmpobject->thirdparty as $key => $value) {
676 if (in_array($key, $arrayoffieldstoexclude)) {
679 if (!in_array($key, array(
680 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
681 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
685 if (!is_object($value) && !is_null($value) && $value !==
'') {
686 $paymentpart->thirdparty->$key = $value;
692 if ($this->element ==
'payment_donation') {
693 $paymentpart->donation =
new stdClass();
695 $paymentpart->invoice =
new stdClass();
698 if ($this->element !=
'payment_various') {
699 foreach ($tmpobject as $key => $value) {
700 if (in_array($key, $arrayoffieldstoexclude)) {
703 if (!in_array($key, array(
704 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
708 if (!is_object($value) && !is_null($value) && $value !==
'') {
709 if ($this->element ==
'payment_donation') {
710 $paymentpart->donation->$key = $value;
711 } elseif ($this->element ==
'payment_various') {
712 $paymentpart->various->$key = $value;
714 $paymentpart->invoice->$key = $value;
719 $paymentpartnumber++;
720 $this->object_data->payment_part[$paymentpartnumber] = $paymentpart;
723 } elseif (!empty(
$object->amount)) {
724 $totalamount =
$object->amount;
727 $this->object_data->amount = $totalamount;
730 $this->object_data->ref =
$object->newref;
732 } elseif ($this->element ==
'payment_salary') {
733 '@phan-var-force PaymentSalary $object';
734 $this->object_data->amounts = array(
$object->amount);
737 $this->object_data->ref =
$object->newref;
739 } elseif ($this->element ==
'subscription') {
740 '@phan-var-force Subscription $object';
741 foreach (
$object as $key => $value) {
742 if (in_array($key, $arrayoffieldstoexclude)) {
745 if (!in_array($key, array(
746 'id',
'datec',
'dateh',
'datef',
'fk_adherent',
'amount',
'import_key',
'statut',
'note'
750 if (!is_object($value) && !is_null($value) && $value !==
'') {
751 $this->object_data->$key = $value;
756 $this->object_data->ref =
$object->newref;
758 } elseif ($this->element ==
'stockmouvement') {
759 '@phan-var-force StockTransfer $object';
760 foreach (
$object as $key => $value) {
761 if (in_array($key, $arrayoffieldstoexclude)) {
764 if (!is_object($value) && !is_null($value) && $value !==
'') {
765 $this->object_data->$key = $value;
770 foreach (
$object as $key => $value) {
771 if (in_array($key, $arrayoffieldstoexclude)) {
774 if (!is_object($value) && !is_null($value) && $value !==
'') {
775 $this->object_data->$key = $value;
780 $this->object_data->ref =
$object->newref;
786 $this->object_data = json_decode(json_encode($this->object_data, JSON_FORCE_OBJECT),
false);
802 $this->error =
'BadParameter';
806 $sql =
"SELECT b.rowid, b.date_creation, b.signature, b.signature_line, b.amounts, b.action, b.element, b.fk_object, b.entity,";
807 $sql .=
" b.certified, b.tms, b.fk_user, b.user_fullname, b.date_object, b.ref_object, b.object_data, b.object_version";
808 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog as b";
810 $sql .=
" WHERE b.rowid = ".((int) $id);
813 $resql = $this->db->query($sql);
815 $obj = $this->db->fetch_object($resql);
817 $this->
id = $obj->rowid;
818 $this->entity = $obj->entity;
820 $this->date_creation = $this->db->jdate($obj->date_creation);
821 $this->date_modification = $this->db->jdate($obj->tms);
823 $this->amounts = (float) $obj->amounts;
824 $this->action = $obj->action;
825 $this->element = $obj->element;
827 $this->fk_object = $obj->fk_object;
828 $this->date_object = $this->db->jdate($obj->date_object);
829 $this->ref_object = $obj->ref_object;
831 $this->fk_user = $obj->fk_user;
832 $this->user_fullname = $obj->user_fullname;
835 $this->object_version = $obj->object_version;
837 $this->signature = $obj->signature;
838 $this->signature_line = $obj->signature_line;
839 $this->certified = ($obj->certified == 1);
843 $langs->load(
"errors");
844 $this->error = $langs->trans(
"ErrorRecordNotFound");
848 $this->error = $this->db->error();
916 public function create($user, $forcesignature =
'')
918 global
$conf, $langs;
920 $langs->load(
'blockedlog');
923 $this->amounts = (float) $this->amounts;
925 dol_syslog(get_class($this).
'::create action='.$this->action.
' fk_user='.$this->fk_user.
' user_fullname='.$this->user_fullname, LOG_DEBUG);
928 if (!isset($this->amounts)) {
929 $this->error = $langs->trans(
"BlockLogNeedAmountsValue");
934 if (empty($this->element)) {
935 $this->error = $langs->trans(
"BlockLogNeedElement");
940 if (empty($this->action)) {
941 $this->error = $langs->trans(
"BadParameterWhenCallingCreateOfBlockedLog");
945 if (empty($this->fk_user)) {
946 $this->user_fullname =
'(Anonymous)';
949 $this->date_creation =
dol_now();
951 $this->object_version = DOL_VERSION;
962 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
964 $this->signature_line =
dol_hash($concatenatedata,
'5');
965 $this->signature =
dol_hash($previoushash.$concatenatedata,
'5');
966 if ($forcesignature) {
967 $this->signature = $forcesignature;
971 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog (";
972 $sql .=
" date_creation,";
975 $sql .=
" signature,";
976 $sql .=
" signature_line,";
978 $sql .=
" fk_object,";
979 $sql .=
" date_object,";
980 $sql .=
" ref_object,";
981 $sql .=
" object_data,";
982 $sql .=
" object_version,";
983 $sql .=
" certified,";
985 $sql .=
" user_fullname,";
987 $sql .=
" debuginfo";
988 $sql .=
") VALUES (";
989 $sql .=
"'".$this->db->idate($this->date_creation).
"',";
990 $sql .=
"'".$this->db->escape($this->action).
"',";
991 $sql .= $this->amounts.
",";
992 $sql .=
"'".$this->db->escape($this->signature).
"',";
993 $sql .=
"'".$this->db->escape($this->signature_line).
"',";
994 $sql .=
"'".$this->db->escape($this->element).
"',";
995 $sql .= (int) $this->fk_object.
",";
996 $sql .=
"'".$this->db->idate($this->date_object).
"',";
997 $sql .=
"'".$this->db->escape($this->ref_object).
"',";
999 $sql .=
"'".$this->db->escape($this->object_version).
"',";
1001 $sql .= $this->fk_user.
",";
1002 $sql .=
"'".$this->db->escape($this->user_fullname).
"',";
1003 $sql .= ($this->entity ? $this->entity :
$conf->entity).
",";
1004 $sql .=
"'".$this->db->escape($this->debuginfo).
"'";
1015 $res = $this->db->query($sql);
1017 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog");
1022 $this->db->commit();
1026 $this->db->rollback();
1030 $this->error = $this->db->error();
1031 $this->db->rollback();