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',
536 'module_source',
'pos_source'
540 if ($key ==
'lines') {
542 foreach ($value as $tmpline) {
544 foreach ($tmpline as $keyline => $valueline) {
545 if (!in_array($keyline, array(
546 'ref',
'product_type',
'product_label',
549 'vat_src_code',
'tva_tx',
'localtax1_tx',
'localtax2_tx',
550 'total_ht',
'total_tva',
'total_ttc',
'total_localtax1',
'total_localtax2',
551 'multicurrency_code',
'multicurrency_total_ht',
'multicurrency_total_tva',
'multicurrency_total_ttc',
552 'info_bits',
'special_code',
557 if (empty($this->object_data->invoiceline[$lineid]) || !is_object($this->object_data->invoiceline[$lineid])) {
558 $this->object_data->invoiceline[$lineid] =
new stdClass();
561 if (!is_object($valueline) && !is_null($valueline) && $valueline !==
'') {
562 $this->object_data->invoiceline[$lineid]->$keyline = $valueline;
566 } elseif (!is_object($value) && !is_null($value) && $value !==
'') {
567 $this->object_data->$key = $value;
572 $this->object_data->ref =
$object->newref;
574 } elseif ($this->element ==
'invoice_supplier') {
575 '@phan-var-force FactureFournisseur $object';
576 foreach (
$object as $key => $value) {
577 if (in_array($key, $arrayoffieldstoexclude)) {
580 if (!in_array($key, array(
581 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
585 if (!is_object($value) && !is_null($value) && $value !==
'') {
586 $this->object_data->$key = $value;
591 $this->object_data->ref =
$object->newref;
593 } elseif ($this->element ==
'payment' || $this->element ==
'payment_supplier' || $this->element ==
'payment_donation' || $this->element ==
'payment_various') {
594 '@phan-var-force Paiement|PaiementFourn|PaymentDonation|PaymentVarious $object';
598 $this->object_data->ref =
$object->ref;
599 $this->object_data->date = $datepayment;
600 $this->object_data->type_code =
dol_getIdFromCode($this->db, $paymenttypeid,
'c_paiement',
'id',
'code');
602 if (!empty(
$object->num_payment)) {
603 $this->object_data->payment_num =
$object->num_payment;
605 if (!empty(
$object->note_private)) {
606 $this->object_data->note_private =
$object->note_private;
615 $paymentpartnumber = 0;
616 foreach (
$object->amounts as $objid => $amount) {
617 if (empty($amount)) {
621 $totalamount += $amount;
624 if ($this->element ==
'payment_supplier') {
625 include_once DOL_DOCUMENT_ROOT.
'/fourn/class/fournisseur.facture.class.php';
627 } elseif ($this->element ==
'payment') {
628 include_once DOL_DOCUMENT_ROOT.
'/compta/facture/class/facture.class.php';
629 $tmpobject =
new Facture($this->db);
630 } elseif ($this->element ==
'payment_donation') {
631 include_once DOL_DOCUMENT_ROOT.
'/don/class/don.class.php';
632 $tmpobject =
new Don($this->db);
633 } elseif ($this->element ==
'payment_various') {
634 include_once DOL_DOCUMENT_ROOT.
'/compta/bank/class/paymentvarious.class.php';
638 if (!is_object($tmpobject)) {
642 $result = $tmpobject->fetch($objid);
645 $this->error = $tmpobject->error;
646 $this->errors = $tmpobject->errors;
647 dol_syslog(
"Failed to fetch object with id ".$objid, LOG_ERR);
652 $paymentpart->amount = $amount;
654 if (!in_array($this->element, array(
'payment_donation',
'payment_various'))) {
655 $result = $tmpobject->fetch_thirdparty();
657 $this->error =
'Failed to fetch thirdparty for object with id '.$tmpobject->id;
658 $this->errors[] = $this->error;
659 dol_syslog(
"Failed to fetch thirdparty for object with id ".$tmpobject->id, LOG_ERR);
661 } elseif ($result < 0) {
662 $this->error = $tmpobject->error;
663 $this->errors = $tmpobject->errors;
667 $paymentpart->thirdparty =
new stdClass();
668 foreach ($tmpobject->thirdparty as $key => $value) {
669 if (in_array($key, $arrayoffieldstoexclude)) {
672 if (!in_array($key, array(
673 'name',
'name_alias',
'ref_ext',
'address',
'zip',
'town',
'state_code',
'country_code',
'idprof1',
'idprof2',
'idprof3',
'idprof4',
'idprof5',
'idprof6',
'phone',
'fax',
'email',
'barcode',
674 'tva_intra',
'localtax1_assuj',
'localtax1_value',
'localtax2_assuj',
'localtax2_value',
'managers',
'capital',
'typent_code',
'forme_juridique_code',
'code_client',
'code_fournisseur'
678 if (!is_object($value) && !is_null($value) && $value !==
'') {
679 $paymentpart->thirdparty->$key = $value;
685 if ($this->element ==
'payment_donation') {
686 $paymentpart->donation =
new stdClass();
688 $paymentpart->invoice =
new stdClass();
691 if ($this->element !=
'payment_various') {
692 foreach ($tmpobject as $key => $value) {
693 if (in_array($key, $arrayoffieldstoexclude)) {
696 if (!in_array($key, array(
697 'ref',
'ref_client',
'ref_supplier',
'date',
'datef',
'type',
'total_ht',
'total_tva',
'total_ttc',
'localtax1',
'localtax2',
'revenuestamp',
'datepointoftax',
'note_public'
701 if (!is_object($value) && !is_null($value) && $value !==
'') {
702 if ($this->element ==
'payment_donation') {
703 $paymentpart->donation->$key = $value;
704 } elseif ($this->element ==
'payment_various') {
705 $paymentpart->various->$key = $value;
707 $paymentpart->invoice->$key = $value;
712 $paymentpartnumber++;
713 $this->object_data->payment_part[$paymentpartnumber] = $paymentpart;
716 } elseif (!empty(
$object->amount)) {
717 $totalamount =
$object->amount;
720 $this->object_data->amount = $totalamount;
723 $this->object_data->ref =
$object->newref;
725 } elseif ($this->element ==
'payment_salary') {
726 '@phan-var-force PaymentSalary $object';
727 $this->object_data->amounts = array(
$object->amount);
730 $this->object_data->ref =
$object->newref;
732 } elseif ($this->element ==
'subscription') {
733 '@phan-var-force Subscription $object';
734 foreach (
$object as $key => $value) {
735 if (in_array($key, $arrayoffieldstoexclude)) {
738 if (!in_array($key, array(
739 'id',
'datec',
'dateh',
'datef',
'fk_adherent',
'amount',
'import_key',
'statut',
'note'
743 if (!is_object($value) && !is_null($value) && $value !==
'') {
744 $this->object_data->$key = $value;
749 $this->object_data->ref =
$object->newref;
751 } elseif ($this->element ==
'stockmouvement') {
752 '@phan-var-force StockTransfer $object';
753 foreach (
$object as $key => $value) {
754 if (in_array($key, $arrayoffieldstoexclude)) {
757 if (!is_object($value) && !is_null($value) && $value !==
'') {
758 $this->object_data->$key = $value;
763 foreach (
$object as $key => $value) {
764 if (in_array($key, $arrayoffieldstoexclude)) {
767 if (!is_object($value) && !is_null($value) && $value !==
'') {
768 $this->object_data->$key = $value;
773 $this->object_data->ref =
$object->newref;
779 $this->object_data = json_decode(json_encode($this->object_data, JSON_FORCE_OBJECT),
false);
795 $this->error =
'BadParameter';
799 $sql =
"SELECT b.rowid, b.date_creation, b.signature, b.signature_line, b.amounts, b.action, b.element, b.fk_object, b.entity,";
800 $sql .=
" b.certified, b.tms, b.fk_user, b.user_fullname, b.date_object, b.ref_object, b.object_data, b.object_version";
801 $sql .=
" FROM ".MAIN_DB_PREFIX.
"blockedlog as b";
803 $sql .=
" WHERE b.rowid = ".((int) $id);
806 $resql = $this->db->query($sql);
808 $obj = $this->db->fetch_object($resql);
810 $this->
id = $obj->rowid;
811 $this->entity = $obj->entity;
813 $this->date_creation = $this->db->jdate($obj->date_creation);
814 $this->date_modification = $this->db->jdate($obj->tms);
816 $this->amounts = (float) $obj->amounts;
817 $this->action = $obj->action;
818 $this->element = $obj->element;
820 $this->fk_object = $obj->fk_object;
821 $this->date_object = $this->db->jdate($obj->date_object);
822 $this->ref_object = $obj->ref_object;
824 $this->fk_user = $obj->fk_user;
825 $this->user_fullname = $obj->user_fullname;
828 $this->object_version = $obj->object_version;
830 $this->signature = $obj->signature;
831 $this->signature_line = $obj->signature_line;
832 $this->certified = ($obj->certified == 1);
836 $langs->load(
"blockedlog");
837 $this->error = $langs->trans(
"RecordNotFound");
841 $this->error = $this->db->error();
909 public function create($user, $forcesignature =
'')
911 global
$conf, $langs;
913 $langs->load(
'blockedlog');
916 $this->amounts = (float) $this->amounts;
918 dol_syslog(get_class($this).
'::create action='.$this->action.
' fk_user='.$this->fk_user.
' user_fullname='.$this->user_fullname, LOG_DEBUG);
921 if (!isset($this->amounts)) {
922 $this->error = $langs->trans(
"BlockLogNeedAmountsValue");
927 if (empty($this->element)) {
928 $this->error = $langs->trans(
"BlockLogNeedElement");
933 if (empty($this->action)) {
934 $this->error = $langs->trans(
"BadParameterWhenCallingCreateOfBlockedLog");
938 if (empty($this->fk_user)) {
939 $this->user_fullname =
'(Anonymous)';
942 $this->date_creation =
dol_now();
944 $this->object_version = DOL_VERSION;
953 include_once DOL_DOCUMENT_ROOT.
'/core/lib/security.lib.php';
955 $this->signature_line =
dol_hash($keyforsignature,
'5');
956 $this->signature =
dol_hash($previoushash.$keyforsignature,
'5');
957 if ($forcesignature) {
958 $this->signature = $forcesignature;
962 $sql =
"INSERT INTO ".MAIN_DB_PREFIX.
"blockedlog (";
963 $sql .=
" date_creation,";
966 $sql .=
" signature,";
967 $sql .=
" signature_line,";
969 $sql .=
" fk_object,";
970 $sql .=
" date_object,";
971 $sql .=
" ref_object,";
972 $sql .=
" object_data,";
973 $sql .=
" object_version,";
974 $sql .=
" certified,";
976 $sql .=
" user_fullname,";
978 $sql .=
") VALUES (";
979 $sql .=
"'".$this->db->idate($this->date_creation).
"',";
980 $sql .=
"'".$this->db->escape($this->action).
"',";
981 $sql .= $this->amounts.
",";
982 $sql .=
"'".$this->db->escape($this->signature).
"',";
983 $sql .=
"'".$this->db->escape($this->signature_line).
"',";
984 $sql .=
"'".$this->db->escape($this->element).
"',";
985 $sql .= (int) $this->fk_object.
",";
986 $sql .=
"'".$this->db->idate($this->date_object).
"',";
987 $sql .=
"'".$this->db->escape($this->ref_object).
"',";
989 $sql .=
"'".$this->db->escape($this->object_version).
"',";
991 $sql .= $this->fk_user.
",";
992 $sql .=
"'".$this->db->escape($this->user_fullname).
"',";
993 $sql .= ($this->entity ? $this->entity :
$conf->entity);
1004 $res = $this->db->query($sql);
1006 $id = $this->db->last_insert_id(MAIN_DB_PREFIX.
"blockedlog");
1011 $this->db->commit();
1015 $this->db->rollback();
1019 $this->error = $this->db->error();
1020 $this->db->rollback();