11 include_once
'./Services/Payment/classes/class.ilPaymentVendors.php';
12 include_once
'./Services/Payment/classes/class.ilPaymentTrustees.php';
47 $this->admin_view = $a_admin_view;
48 $this->user_id = $a_user_id;
52 include_once
'./Services/Payment/classes/class.ilGeneralSettings.php';
54 $this->currency_unit = $genSet->get(
'currency_unit');
65 return $this->booking_id = $a_booking_id;
73 $this->transaction = $a_transaction;
77 return $this->transaction;
81 $this->pobject_id = $a_pobject_id;
85 return $this->pobject_id;
89 $this->customer_id = $a_customer_id;
93 return $this->customer_id;
97 $this->vendor_id = $a_vendor_id;
101 return $this->vendor_id;
105 $this->pay_method = $a_pay_method;
113 $this->order_date = $a_order_date;
117 return $this->order_date;
121 $this->duration = $a_duration;
125 return $this->duration;
129 if($a_unlimited_duration ==
'' || null) $a_unlimited_duration = 0;
130 $this->unlimited_duration = $a_unlimited_duration;
135 return $this->unlimited_duration;
140 $this->price = $a_price;
148 if($a_discount == null) $a_discount = 0;
149 $this->discount = $a_discount;
153 if($this->discount == null) $this->discount = 0;
154 return $this->discount;
158 $this->payed = $a_payed;
166 $this->access = $a_access;
174 $this->voucher = $a_voucher;
182 $this->transaction_extern = $a_transaction_extern;
186 return $this->transaction_extern;
195 $street = $a_street.
' '.$a_house_nr;
204 $this->po_box = $a_po_box;
213 $this->zipcode = $a_zipcode;
221 $this->city = $a_city;
230 $this->country = $a_country;
235 $this->vat_unit = $a_vat_unit;
240 return $this->vat_unit;
244 $this->vat_rate = $a_vat_rate;
248 return $this->vat_rate;
252 $this->object_title = $a_object_title;
256 return $this->object_title;
261 $this->email_extern = $a_email_extern;
270 $this->name_extern = $a_name_extern;
278 $this->currency_unit = $a_currency_unit;
287 $next_id = $this->db->nextId(
'payment_statistic');
291 $statement = $this->db->manipulateF(
'
292 INSERT INTO payment_statistic
324 ( %s,%s,%s,%s,%s,%s,%s,%s,%s,%s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s, %s,%s,%s,%s,%s)',
381 $statement = $this->db->manipulateF(
'
382 INSERT INTO payment_statistic
407 ( %s,%s,%s,%s,%s,%s,%s,%s,%s,%s, %s,%s,%s,%s,%s,%s,%s,%s,%s,%s)',
459 $statement = $this->db->manipulateF(
'
460 UPDATE payment_statistic
463 WHERE booking_id = %s',
464 array(
'integer',
'integer',
'integer'),
472 public function delete()
476 $statement = $this->db->manipulateF(
'
477 DELETE FROM payment_statistic WHERE booking_id = %s',
489 if(ANONYMOUS_USER_ID == $a_usr_id)
492 $res = $this->db->queryf(
'
493 SELECT * from payment_statistic ps, payment_objects po
494 WHERE ps.pobject_id = po.pobject_id
496 ORDER BY order_date DESC',
501 while(
$row = $this->db->fetchAssoc(
$res))
503 $booking[
$row[
'booking_id']] =
$row;
506 return $booking ? $booking : array();
511 return $this->bookings ? $this->bookings : array();
516 $res = $this->db->queryf(
'
517 SELECT * FROM payment_statistic ps, payment_objects po
518 WHERE ps.pobject_id = po.pobject_id
519 AND booking_id = %s',
521 array($a_booking_id));
523 while(
$row = $this->db->fetchObject(
$res))
527 return $booking ? $booking : array();
535 $res = $ilDB->queryf(
536 'SELECT COUNT(booking_id) bid FROM payment_statistic
537 WHERE b_vendor_id = %s',
539 array($a_vendor_id));
541 while(
$row = $ilDB->fetchAssoc(
$res))
552 if(ANONYMOUS_USER_ID == $a_vendor_id)
555 $res = $ilDB->queryf(
'
556 SELECT COUNT(booking_id) bid FROM payment_statistic
557 WHERE customer_id = %s',
559 array($a_vendor_id));
561 while(
$row = $ilDB->fetchObject(
$res))
572 $res = $ilDB->queryf(
'
573 SELECT COUNT(booking_id) bid FROM payment_statistic
574 WHERE pobject_id = %s',
576 array($a_pobject_id));
578 while(
$row = $ilDB->fetchObject(
$res))
585 public function _hasAccess($a_pobject_id, $a_user_id = 0, $a_transaction = 0)
587 global
$ilDB, $ilias, $ilUser;
589 if(ANONYMOUS_USER_ID == $ilUser->getId() && !$a_transaction)
596 $res = $ilDB->queryf(
'
597 SELECT * FROM payment_statistic
598 WHERE pobject_id = %s
601 AND access_granted = %s',
602 array(
'integer',
'text',
'integer',
'integer'),
603 array($a_pobject_id, $a_transaction,
'1',
'1'));
608 $usr_id = $a_user_id ? $a_user_id : $ilias->account->getId();
610 $res = $ilDB->queryf(
'
611 SELECT * FROM payment_statistic
612 WHERE pobject_id = %s
615 AND access_granted = %s',
616 array(
'integer',
'integer',
'integer',
'integer'),
617 array($a_pobject_id,
$usr_id,
'1',
'1'));
619 while(
$row = $ilDB->fetchObject(
$res))
621 $orderDateYear = date(
"Y",
$row->order_date);
622 $orderDateMonth = date(
"m",
$row->order_date);
623 $orderDateDay = date(
"d",
$row->order_date);
624 $orderDateHour = date(
"H",
$row->order_date);
625 $orderDateMinute = date(
"i",
$row->order_date);
626 $orderDateSecond = date(
"s",
$row->order_date);
628 if(
$row->duration != 0)
630 if (($orderDateMonth +
$row->duration) > 12)
632 $years = floor(($orderDateMonth +
$row->duration) / 12);
633 $months = ($orderDateMonth +
$row->duration) - (12 * $years);
634 $orderDateYear += $years;
635 $orderDateMonth = $months;
639 $orderDateMonth +=
$row->duration;
641 $startDate = date(
"Y-m-d H:i:s",
$row->order_date);
642 $endDate = date(
"Y-m-d H:i:s", mktime($orderDateHour, $orderDateMinute, $orderDateSecond, $orderDateMonth, $orderDateDay, $orderDateYear));
643 if (date(
"Y-m-d H:i:s") >= $startDate &&
644 date(
"Y-m-d H:i:s") <= $endDate)
657 if(ANONYMOUS_USER_ID == $a_user_id)
659 $usr_id = $a_user_id ? $a_user_id : $ilias->account->getId();
661 $res = $this->db->queryf(
'
662 SELECT * FROM payment_statistic
663 WHERE pobject_id = %s
666 AND access_granted = %s',
667 array(
'integer',
'integer',
'integer',
'integer'),
668 array($a_pobject_id,
$usr_id,
'1',
'1'));
670 while(
$row = $this->db->fetchObject(
$res))
672 $orderDateYear = date(
"Y",
$row->order_date);
673 $orderDateMonth = date(
"m",
$row->order_date);
674 $orderDateDay = date(
"d",
$row->order_date);
675 $orderDateHour = date(
"H",
$row->order_date);
676 $orderDateMinute = date(
"i",
$row->order_date);
677 $orderDateSecond = date(
"s",
$row->order_date);
678 if (($orderDateMonth +
$row->duration) > 12)
680 $years = floor(($orderDateMonth +
$row->duration) / 12);
681 $months = ($orderDateMonth +
$row->duration) - (12 * $years);
682 $orderDateYear += $years;
683 $orderDateMonth = $months;
687 $orderDateMonth +=
$row->duration;
689 $startDate = date(
"Y-m-d H:i:s",
$row->order_date);
690 $endDate = date(
"Y-m-d H:i:s", mktime($orderDateHour, $orderDateMinute, $orderDateSecond, $orderDateMonth, $orderDateDay, $orderDateYear));
691 if (date(
"Y-m-d H:i:s") >= $startDate &&
692 date(
"Y-m-d H:i:s") <= $endDate)
695 "activation_start" =>
$row->order_date,
696 "activation_end" => mktime($orderDateHour, $orderDateMinute, $orderDateSecond, $orderDateMonth, $orderDateDay, $orderDateYear)
710 $res = $this->db->queryf (
'
711 SELECT COUNT(booking_id) bid FROM payment_statistc
712 WHERE pay_method = %s',
716 while(
$row = $this->db->fetchObject(
$res))
723 $res = $this->db->queryf (
'
724 SELECT COUNT(booking_id) bid FROM payment_statistc
725 WHERE pay_method = %s',
729 while(
$row = $this->db->fetchObject(
$res))
736 $res = $this->db->queryf (
'
737 SELECT COUNT(booking_id) bid FROM payment_statistc
738 WHERE pay_method = %s',
742 while(
$row = $this->db->fetchObject(
$res))
749 $res = $this->db->queryf (
'
750 SELECT COUNT(booking_id) bid FROM payment_statistc
751 WHERE pay_method = %s',
755 while(
$row = $this->db->fetchObject(
$res))
773 if(ANONYMOUS_USER_ID == $ilUser->getId())
777 $data_types = array();
779 $query =
'SELECT * FROM payment_statistic ps '
780 .
'INNER JOIN payment_objects po ON po.pobject_id = ps.pobject_id ';
781 if(
$_SESSION[
'pay_statistics'][
'customer'])
783 $query .=
'LEFT JOIN usr_data ud ON ud.usr_id = ps.customer_id ';
785 if(
$_SESSION[
'pay_statistics'][
'vendor'] && $this->admin_view)
787 $query .=
'LEFT JOIN usr_data udv ON udv.usr_id = ps.b_vendor_id ';
790 if (
$_SESSION[
'pay_statistics'][
'transaction_value'] !=
'')
792 if (
$_SESSION[
'pay_statistics'][
'transaction_type'] == 0)
794 $query .=
"AND transaction_extern LIKE %s ";
795 $data_types[] =
'text';
798 else if (
$_SESSION[
'pay_statistics'][
'transaction_type'] == 1)
800 $query .=
"AND transaction_extern LIKE %s ";
801 $data_types[] =
'text';
802 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'transaction_value'];
805 if (
$_SESSION[
'pay_statistics'][
'customer'] !=
'')
807 $query .=
"AND ud.login LIKE %s ";
808 $data_types[] =
'text';
809 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'customer'].
'%';
812 if (
$_SESSION[
'pay_statistics'][
'from'][
'date'][
'd'] !=
'' &&
813 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'm'] !=
'' &&
814 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'y'] !=
'')
817 $from = mktime(0, 0, 0,
$_SESSION[
'pay_statistics'][
'from'][
'date'][
'm'],
818 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'd'],
819 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'y']);
820 $query .=
'AND order_date >= %s ';
821 $data_types[] =
'integer';
824 if (
$_SESSION[
'pay_statistics'][
'til'][
'date'][
'd'] !=
'' &&
825 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'm'] !=
'' &&
826 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'y'] !=
'')
828 $til = mktime(23, 59, 59,
$_SESSION[
'pay_statistics'][
'til'][
'date'][
'm'],
829 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'd'],
830 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'y']);
831 $query .=
'AND order_date <= %s ';
832 $data_types[] =
'integer';
835 if (
$_SESSION[
'pay_statistics'][
'payed'] ==
'0' ||
836 $_SESSION[
'pay_statistics'][
'payed'] ==
'1')
838 $query .=
'AND payed = %s ';
839 $data_types[] =
'integer';
842 if (
$_SESSION[
'pay_statistics'][
'access'] ==
'0' ||
843 $_SESSION[
'pay_statistics'][
'access'] ==
'1')
845 $query .=
'AND access_granted = %s ';
846 $data_types[] =
'integer';
849 if (
$_SESSION[
'pay_statistics'][
'pay_method'] ==
'1' ||
850 $_SESSION[
'pay_statistics'][
'pay_method'] ==
'2' ||
851 $_SESSION[
'pay_statistics'][
'pay_method'] ==
'3')
853 $query .=
'AND b_pay_method = %s ';
854 $data_types[] =
'integer';
858 if(!$this->admin_view)
863 if (is_array($vendors) &&
866 $query .=
' AND '.$this->db->in(
'ps.b_vendor_id', $vendors,
false,
'integer').
' ';
868 else if(is_array($vendors) && count($vendors) == 1)
870 $query .=
'AND ps.b_vendor_id = %s ';
871 $data[] = $vendors[
'0'];
872 $data_types[] =
'integer';
874 if((
int)
$_SESSION[
'pay_statistics'][
'filter_title_id'])
876 $query .=
"AND po.ref_id = ".(int)$_SESSION[
'pay_statistics'][
'filter_title_id'].
" ";
881 if(
$_SESSION[
'pay_statistics'][
'vendor'])
883 $query .=
'AND udv.login LIKE %s ';
885 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'vendor'].
'%';
886 $data_types[] =
'text';
889 if((
int)
$_SESSION[
'pay_statistics'][
'adm_filter_title_id'])
891 $query .=
"AND po.ref_id = ".(int)
$_SESSION[
'pay_statistics'][
'adm_filter_title_id'].
" ";
894 $query .=
'ORDER BY order_date DESC';
896 $cnt_data = count(
$data);
897 $cnt_data_types = count($data_types);
899 if($cnt_data == 0 || $cnt_data_types == 0)
908 while(
$row = $this->db->fetchAssoc(
$res))
910 $this->bookings[
$row[
'booking_id']] =
$row;
934 return $vendors ? $vendors : array();
942 $query =
'SELECT * FROM payment_statistic as ps, payment_objects as po
943 WHERE ps.pobject_id = po.pobject_id
945 AND transaction = %s';
948 $res = $ilDB->queryF(
$query, array(
'integer',
'text'), array($a_user_id, $a_transaction_nr));
949 while(
$row = $ilDB->fetchAssoc(
$res))
961 $query =
'SELECT * FROM payment_statistic
962 WHERE customer_id = %s
964 ORDER BY order_date DESC';
966 $res = $ilDB->queryF(
$query, array(
'integer'), array($a_user_id));
967 while(
$row = $ilDB->fetchAssoc(
$res))
969 $booking[
$row[
'booking_id']] =
$row;
971 return $booking ? $booking : array();
978 $res = $ilDB->queryF(
'
979 SELECT * FROM payment_statistic WHERE b_pay_method = %s', array(
'integer'), array(
$pay_method));
982 while(
$row = $ilDB->fetchAssoc(
$res))
989 return $booking ? $booking : array();
997 UPDATE payment_statistic
1003 WHERE b_pay_method = %s',
1012 $trans_exp = explode(
'_', $a_transaction);
1015 $res = $ilDB->queryF(
'SELECT * FROM payment_statistic
1016 WHERE transaction = %s
1018 AND access_granted = %s
1019 AND customer_id = %s',
1020 array(
'text',
'integer',
'integer',
'integer'),
1021 array($a_transaction, 1,1, (
int)
$user_id));
1030 $query =
'SELECT DISTINCT(po.ref_id) ref_id FROM payment_statistic ps, payment_objects po';
1031 $query .=
" WHERE ps.pobject_id = po.pobject_id ";
1033 if(!$this->admin_view)
1037 if (is_array($vendors) && count($vendors) > 1)
1043 $data_types[] =
'integer';
1045 $str_data = implode(
',',$arr_data);
1047 $query .=
'AND ps.b_vendor_id IN ('.$str_data.
') ';
1050 else if(is_array($vendors) && count($vendors) == 1)
1052 $query .=
'AND ps.b_vendor_id = %s ';
1053 $data[] = $vendors[
'0'];
1054 $data_types[] =
'integer';
1057 $query .=
"ORDER BY order_date DESC";
1059 if(!$data_types && !
$data)
1068 $rows[] =
$row->ref_id;
1070 return is_array($rows) ? $rows : array();