253 if ($this->element ===
'facture') {
254 require_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
257 if (
$object->fetch($this->fk_object) > 0) {
260 $this->error = (string) (((
int) $this->error) + 1);
263 if ($this->element ===
'invoice_supplier') {
264 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
267 if (
$object->fetch($this->fk_object) > 0) {
270 $this->error = (string) (((
int) $this->error) + 1);
272 } elseif ($this->element ===
'payment') {
273 require_once DOL_DOCUMENT_ROOT.
'/compta/paiement/class/paiement.class.php';
276 if (
$object->fetch($this->fk_object) > 0) {
279 $this->error = (string) (((
int) $this->error) + 1);
281 } elseif ($this->element ===
'payment_supplier') {
282 require_once DOL_DOCUMENT_ROOT.
'/fourn/class/paiementfourn.class.php';
285 if (
$object->fetch($this->fk_object) > 0) {
288 $this->error = (string) (((
int) $this->error) + 1);
290 } elseif ($this->element ===
'payment_donation') {
291 require_once DOL_DOCUMENT_ROOT.
'/don/class/paymentdonation.class.php';
294 if (
$object->fetch($this->fk_object) > 0) {
297 $this->error = (string) (((
int) $this->error) + 1);
299 } elseif ($this->element ===
'payment_various') {
300 require_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
303 if (
$object->fetch($this->fk_object) > 0) {
306 $this->error = (string) (((
int) $this->error) + 1);
308 } elseif ($this->element ===
'don' || $this->element ===
'donation') {
309 require_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
312 if (
$object->fetch($this->fk_object) > 0) {
315 $this->error = (string) (((
int) $this->error) + 1);
317 } elseif ($this->element ===
'subscription') {
318 require_once DOL_DOCUMENT_ROOT.
'/adherents/class/subscription.class.php';
321 if (
$object->fetch($this->fk_object) > 0) {
324 $this->error = (string) (((
int) $this->error) + 1);
326 } elseif ($this->element ===
'cashcontrol') {
327 require_once DOL_DOCUMENT_ROOT.
'/compta/cashcontrol/class/cashcontrol.class.php';
330 if (
$object->fetch($this->fk_object) > 0) {
333 $this->error = (string) (((
int) $this->error) + 1);
335 } elseif ($this->element ===
'stockmouvement') {
336 require_once DOL_DOCUMENT_ROOT.
'/product/stock/class/mouvementstock.class.php';
339 if (
$object->fetch($this->fk_object) > 0) {
342 $this->error = (string) (((
int) $this->error) + 1);
344 } elseif ($this->element ===
'project') {
345 require_once DOL_DOCUMENT_ROOT.
'/projet/class/project.class.php';
348 if (
$object->fetch($this->fk_object) > 0) {
351 $this->error = (string) (((
int) $this->error) + 1);
353 } elseif ($this->action ==
'BLOCKEDLOG_EXPORT') {
354 return '<i class="opacitymedium">'.$langs->trans(
"logBLOCKEDLOG_EXPORT").
'</i>';
355 } elseif ($this->action ==
'MODULE_SET') {
356 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogEnabled").
'</i>';
357 } elseif ($this->action ==
'MODULE_RESET') {
358 if ($this->signature ==
'0000000000') {
359 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabled").
'</i>';
361 return '<i class="opacitymedium">'.$langs->trans(
"BlockedLogDisabledBis").
'</i>';
365 return '<i class="opacitymedium">'.$langs->trans(
'ImpossibleToReloadObject', $this->element, $this->fk_object).
'</i>';
406 global $langs, $user, $mysoc;
408 if (is_object($fuser)) {
415 $this->action = $action;
417 $this->amounts = $amounts;
419 if (
$object->element ==
'payment' ||
$object->element ==
'payment_supplier') {
420 '@phan-var-force Paiement|PaiementFourn $object';
422 } elseif (
$object->element ==
'payment_salary') {
423 '@phan-var-force PaymentSalary $object';
424 $this->date_object =
$object->datev;
425 } elseif (
$object->element ==
'payment_donation' ||
$object->element ==
'payment_various') {
426 '@phan-var-force PaymentDonation $object';
428 } elseif (
$object->element ==
'subscription') {
429 '@phan-var-force Subscription $object';
430 $this->date_object =
$object->dateh;
431 } elseif (
$object->element ==
'cashcontrol') {
432 '@phan-var-force CashControl $object';
433 $this->date_object =
$object->date_creation;
434 } elseif (property_exists(
$object,
'date')) {
436 $this->date_object =
$object->date;
437 } elseif (property_exists(
$object,
'datem')) {
439 $this->date_object =
$object->datem;
445 $this->element =
$object->element;
447 $this->fk_object =
$object->id;
451 $this->object_data =
new stdClass();
453 $arrayoffieldstoexclude = array(
454 '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',
455 'table_element_line',
'ismultientitymanaged',
'isextrafieldmanaged',
464 'fk_delivery_address',
466 'restrictiononfksoc',
470 if ($this->element ==
'cashcontrol') {
471 $arrayoffieldstoexclude = array_merge($arrayoffieldstoexclude, array(
472 'name',
'lastname',
'firstname',
'region',
'region_id',
'region_code',
'state',
'state_id',
'state_code',
'country',
'country_id',
'country_code',
473 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
474 'barcode_type',
'barcode_type_code',
'barcode_type_label',
'barcode_type_coder',
'mode_reglement_id',
'cond_reglement_id',
'mode_reglement',
'cond_reglement',
'shipping_method_id',
475 'fk_incoterms',
'label_incoterms',
'location_incoterms',
'lines'));
479 if (empty(
$object->thirdparty) && method_exists(
$object,
'fetch_thirdparty')) {
482 if (!empty(
$object->thirdparty)) {
483 $this->object_data->thirdparty =
new stdClass();
485 foreach (
$object->thirdparty as $key => $value) {
486 if (in_array($key, $arrayoffieldstoexclude)) {
489 if (!in_array($key, array(
490 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
491 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
495 if (!is_object($value) && !is_null($value) && $value !==
'') {
496 $this->object_data->thirdparty->$key = $value;
502 if (!empty($mysoc)) {
503 $this->object_data->mycompany =
new stdClass();
505 foreach ($mysoc as $key => $value) {
506 if (in_array($key, $arrayoffieldstoexclude)) {
509 if (!in_array($key, array(
510 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
511 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
515 if (!is_object($value) && !is_null($value) && $value !==
'') {
516 $this->object_data->mycompany->$key = $value;
523 $this->fk_user = $user->id;
524 $this->user_fullname = $user->getFullName($langs);
528 if ($this->element ==
'facture') {
529 '@phan-var-force Facture $object';
530 foreach (
$object as $key => $value) {
531 if (in_array($key, $arrayoffieldstoexclude)) {
534 if (!in_array($key, array(
535 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'datev',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public',
'lines'
539 if ($key ==
'lines') {
541 foreach ($value as $tmpline) {
543 foreach ($tmpline as $keyline => $valueline) {
544 if (!in_array($keyline, array(
545 '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'
550 if (empty($this->object_data->invoiceline[$lineid]) || !is_object($this->object_data->invoiceline[$lineid])) {
551 $this->object_data->invoiceline[$lineid] =
new stdClass();
554 if (!is_object($valueline) && !is_null($valueline) && $valueline !==
'') {
555 $this->object_data->invoiceline[$lineid]->$keyline = $valueline;
559 } elseif (!is_object($value) && !is_null($value) && $value !==
'') {
560 $this->object_data->$key = $value;
565 $this->object_data->ref =
$object->newref;
567 } elseif ($this->element ==
'invoice_supplier') {
568 '@phan-var-force FactureFournisseur $object';
569 foreach (
$object as $key => $value) {
570 if (in_array($key, $arrayoffieldstoexclude)) {
573 if (!in_array($key, array(
574 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
578 if (!is_object($value) && !is_null($value) && $value !==
'') {
579 $this->object_data->$key = $value;
584 $this->object_data->ref =
$object->newref;
586 } elseif ($this->element ==
'payment' || $this->element ==
'payment_supplier' || $this->element ==
'payment_donation' || $this->element ==
'payment_various') {
587 '@phan-var-force Paiement|PaiementFourn|PaymentDonation|PaymentVarious $object';
591 $this->object_data->ref =
$object->ref;
592 $this->object_data->date = $datepayment;
593 $this->object_data->type_code =
dol_getIdFromCode($this->db, $paymenttypeid,
'c_paiement',
'id',
'code');
595 if (!empty(
$object->num_payment)) {
596 $this->object_data->payment_num =
$object->num_payment;
598 if (!empty(
$object->note_private)) {
599 $this->object_data->note_private =
$object->note_private;
608 $paymentpartnumber = 0;
609 foreach (
$object->amounts as $objid => $amount) {
610 if (empty($amount)) {
614 $totalamount += $amount;
617 if ($this->element ==
'payment_supplier') {
618 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
620 } elseif ($this->element ==
'payment') {
621 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
622 $tmpobject =
new Facture($this->db);
623 } elseif ($this->element ==
'payment_donation') {
624 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
625 $tmpobject =
new Don($this->db);
626 } elseif ($this->element ==
'payment_various') {
627 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
631 if (!is_object($tmpobject)) {
635 $result = $tmpobject->fetch($objid);
638 $this->error = $tmpobject->error;
639 $this->errors = $tmpobject->errors;
640 dol_syslog(
"Failed to fetch object with id ".$objid, LOG_ERR);
645 $paymentpart->amount = $amount;
647 if (!in_array($this->element, array(
'payment_donation',
'payment_various'))) {
648 $result = $tmpobject->fetch_thirdparty();
650 $this->error =
'Failed to fetch thirdparty for object with id '.$tmpobject->id;
651 $this->errors[] = $this->error;
652 dol_syslog(
"Failed to fetch thirdparty for object with id ".$tmpobject->id, LOG_ERR);
654 } elseif ($result < 0) {
655 $this->error = $tmpobject->error;
656 $this->errors = $tmpobject->errors;
660 $paymentpart->thirdparty =
new stdClass();
661 foreach ($tmpobject->thirdparty as $key => $value) {
662 if (in_array($key, $arrayoffieldstoexclude)) {
665 if (!in_array($key, array(
666 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
667 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
671 if (!is_object($value) && !is_null($value) && $value !==
'') {
672 $paymentpart->thirdparty->$key = $value;
678 if ($this->element ==
'payment_donation') {
679 $paymentpart->donation =
new stdClass();
681 $paymentpart->invoice =
new stdClass();
684 if ($this->element !=
'payment_various') {
685 foreach ($tmpobject as $key => $value) {
686 if (in_array($key, $arrayoffieldstoexclude)) {
689 if (!in_array($key, array(
690 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
694 if (!is_object($value) && !is_null($value) && $value !==
'') {
695 if ($this->element ==
'payment_donation') {
696 $paymentpart->donation->$key = $value;
697 } elseif ($this->element ==
'payment_various') {
698 $paymentpart->various->$key = $value;
700 $paymentpart->invoice->$key = $value;
705 $paymentpartnumber++;
706 $this->object_data->payment_part[$paymentpartnumber] = $paymentpart;
709 } elseif (!empty(
$object->amount)) {
710 $totalamount =
$object->amount;
713 $this->object_data->amount = $totalamount;
716 $this->object_data->ref =
$object->newref;
718 } elseif ($this->element ==
'payment_salary') {
719 '@phan-var-force PaymentSalary $object';
720 $this->object_data->amounts = array(
$object->amount);
723 $this->object_data->ref =
$object->newref;
725 } elseif ($this->element ==
'subscription') {
726 '@phan-var-force Subscription $object';
727 foreach (
$object as $key => $value) {
728 if (in_array($key, $arrayoffieldstoexclude)) {
731 if (!in_array($key, array(
732 'id',
'datec',
'dateh',
'datef',
'fk_adherent',
'amount',
'import_key',
'statut',
'note'
736 if (!is_object($value) && !is_null($value) && $value !==
'') {
737 $this->object_data->$key = $value;
742 $this->object_data->ref =
$object->newref;
744 } elseif ($this->element ==
'stockmouvement') {
745 '@phan-var-force StockTransfer $object';
746 foreach (
$object as $key => $value) {
747 if (in_array($key, $arrayoffieldstoexclude)) {
750 if (!is_object($value) && !is_null($value) && $value !==
'') {
751 $this->object_data->$key = $value;
756 foreach (
$object as $key => $value) {
757 if (in_array($key, $arrayoffieldstoexclude)) {
760 if (!is_object($value) && !is_null($value) && $value !==
'') {
761 $this->object_data->$key = $value;
766 $this->object_data->ref =
$object->newref;
772 $this->object_data = json_decode(json_encode($this->object_data, JSON_FORCE_OBJECT),
false);
788 $this->error =
'BadParameter';
792 $sql =
"SELECT b.rowid, b.date_creation, b.signature, b.signature_line, b.amounts, b.action, b.element, b.fk_object, b.entity,";
793 $sql .=
" b.certified, b.tms, b.fk_user, b.user_fullname, b.date_object, b.ref_object, b.object_data, b.object_version";
794 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog as b";
796 $sql .=
" WHERE b.rowid = ".((int) $id);
799 $resql = $this->db->query($sql);
801 $obj = $this->db->fetch_object($resql);
803 $this->
id = $obj->rowid;
804 $this->entity = $obj->entity;
806 $this->date_creation = $this->db->jdate($obj->date_creation);
807 $this->date_modification = $this->db->jdate($obj->tms);
809 $this->amounts = (float) $obj->amounts;
810 $this->action = $obj->action;
811 $this->element = $obj->element;
813 $this->fk_object = $obj->fk_object;
814 $this->date_object = $this->db->jdate($obj->date_object);
815 $this->ref_object = $obj->ref_object;
817 $this->fk_user = $obj->fk_user;
818 $this->user_fullname = $obj->user_fullname;
821 $this->object_version = $obj->object_version;
823 $this->signature = $obj->signature;
824 $this->signature_line = $obj->signature_line;
825 $this->certified = ($obj->certified == 1);
829 $langs->load(
"blockedlog");
830 $this->error = $langs->trans(
"RecordNotFound");
834 $this->error = $this->db->error();
902 public function create($user, $forcesignature =
'')
904 global
$conf, $langs, $hookmanager;
906 $langs->load(
'blockedlog');
911 $this->amounts = (float) $this->amounts;
913 dol_syslog(get_class($this).
'::create action='.$this->action.
' fk_user='.$this->fk_user.
' user_fullname='.$this->user_fullname, LOG_DEBUG);
916 if (!isset($this->amounts)) {
917 $this->error = $langs->trans(
"BlockLogNeedAmountsValue");
922 if (empty($this->element)) {
923 $this->error = $langs->trans(
"BlockLogNeedElement");
928 if (empty($this->action)) {
929 $this->error = $langs->trans(
"BadParameterWhenCallingCreateOfBlockedLog");
933 if (empty($this->fk_user)) {
934 $this->user_fullname =
'(Anonymous)';
937 $this->date_creation =
dol_now();
939 $this->object_version = DOL_VERSION;
948 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
950 $this->signature_line =
dol_hash($keyforsignature,
'5');
951 $this->signature =
dol_hash($previoushash.$keyforsignature,
'5');
952 if ($forcesignature) {
953 $this->signature = $forcesignature;
957 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog (";
958 $sql .=
" date_creation,";
961 $sql .=
" signature,";
962 $sql .=
" signature_line,";
964 $sql .=
" fk_object,";
965 $sql .=
" date_object,";
966 $sql .=
" ref_object,";
967 $sql .=
" object_data,";
968 $sql .=
" object_version,";
969 $sql .=
" certified,";
971 $sql .=
" user_fullname,";
973 $sql .=
") VALUES (";
974 $sql .=
"'".$this->db->idate($this->date_creation).
"',";
975 $sql .=
"'".$this->db->escape($this->action).
"',";
976 $sql .= $this->amounts.
",";
977 $sql .=
"'".$this->db->escape($this->signature).
"',";
978 $sql .=
"'".$this->db->escape($this->signature_line).
"',";
979 $sql .=
"'".$this->db->escape($this->element).
"',";
980 $sql .= (int) $this->fk_object.
",";
981 $sql .=
"'".$this->db->idate($this->date_object).
"',";
982 $sql .=
"'".$this->db->escape($this->ref_object).
"',";
984 $sql .=
"'".$this->db->escape($this->object_version).
"',";
986 $sql .= $this->fk_user.
",";
987 $sql .=
"'".$this->db->escape($this->user_fullname).
"',";
988 $sql .= ($this->entity ? $this->entity :
$conf->entity);
999 $res = $this->db->query($sql);
1001 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog");
1006 $this->db->commit();
1010 $this->db->rollback();
1014 $this->error = $this->db->error();
1015 $this->db->rollback();