11 include_once
'./Services/Payment/classes/class.ilPaymentVendors.php';
12 include_once
'./Services/Payment/classes/class.ilPaymentTrustees.php';
52 $this->admin_view = $a_admin_view;
53 $this->user_id = $a_user_id;
56 include_once
'./Services/Payment/classes/class.ilPaymentSettings.php';
58 $this->currency_unit = $genSet->get(
'currency_unit');
69 return $this->booking_id = $a_booking_id;
77 $this->transaction = $a_transaction;
81 return $this->transaction;
85 $this->pobject_id = $a_pobject_id;
89 return $this->pobject_id;
93 $this->customer_id = $a_customer_id;
97 return $this->customer_id;
101 $this->vendor_id = $a_vendor_id;
105 return $this->vendor_id;
109 $this->pay_method = $a_pay_method;
117 $this->order_date = $a_order_date;
121 return $this->order_date;
125 $this->duration = $a_duration;
129 return $this->duration;
133 if($a_unlimited_duration ==
'' || null) $a_unlimited_duration = 0;
134 $this->unlimited_duration = $a_unlimited_duration;
139 return $this->unlimited_duration;
144 $this->price = $a_price;
152 if($a_discount == null) $a_discount = 0;
153 $this->discount = $a_discount;
157 if($this->discount == null) $this->discount = 0;
158 return $this->discount;
162 $this->payed = $a_payed;
170 $this->access = $a_access;
178 $this->voucher = $a_voucher;
186 $this->transaction_extern = $a_transaction_extern;
190 return $this->transaction_extern;
199 $street = $a_street.
' '.$a_house_nr;
208 $this->po_box = $a_po_box;
217 $this->zipcode = $a_zipcode;
225 $this->city = $a_city;
234 $this->country = $a_country;
239 $this->vat_unit = $a_vat_unit;
244 return $this->vat_unit;
248 $this->vat_rate = $a_vat_rate;
252 return $this->vat_rate;
256 $this->object_title = $a_object_title;
260 return $this->object_title;
265 $this->email_extern = $a_email_extern;
274 $this->name_extern = $a_name_extern;
282 $this->currency_unit = $a_currency_unit;
291 $this->access_startdate = $a_access_startdate;
300 $this->access_enddate = $a_access_enddate;
309 $this->access_extension = $a_access_extension;
320 $ilDB->setLimit(1,0);
323 $res_1 = $ilDB->queryF(
'SELECT * FROM payment_statistic
324 WHERE pobject_id = %s
327 AND access_enddate = %s',
328 array(
'integer',
'integer',
'integer',
'timestamp'),
332 $row_1 = $ilDB->fetchAssoc($res_1);
333 if(count($row_1) > 0 )
340 $res_2 = $ilDB->queryF(
'SELECT * FROM payment_statistic
341 WHERE pobject_id = %s
343 ORDER BY access_enddate DESC',
344 array(
'integer',
'integer'),
348 $row_2 = $ilDB->fetchAssoc($res_2);
349 if(count($row_2) > 0)
353 $old_enddate = $row_2[
'access_enddate']; # Y-m-d H:i:s
354 $current_date = date(
"Y-m-d H:i:s", $this->
getOrderDate());
356 if($old_enddate <= $current_date)
377 include_once(
'Services/Calendar/classes/class.ilDateTime.php');
380 $start_date = $tmp_ts->getUnixTime();
383 $startDateYear = date(
"Y", $start_date);
384 $startDateMonth = date(
"m", $start_date);
385 $startDateDay = date(
"d", $start_date);
386 $startDateHour = date(
"H", $start_date);
387 $startDateMinute = date(
"i",$start_date);
388 $startDateSecond = date(
"s", $start_date);
390 $access_enddate = date(
"Y-m-d H:i:s", mktime($startDateHour, $startDateMinute, $startDateSecond,
391 $startDateMonth + $duration, $startDateDay, $startDateYear));
411 $next_id = $this->db->nextId(
'payment_statistic');
414 $statement = $this->db->insert(
'payment_statistic',
416 'booking_id' => array(
'integer', $next_id),
418 'pobject_id' => array(
'integer', $this->
getPobjectId()),
420 'b_vendor_id' => array(
'integer', $this->
getVendorId()),
421 'b_pay_method' => array(
'integer', $this->
getPayMethod()),
422 'order_date' => array(
'integer', $this->
getOrderDate()),
424 'price' => array(
'float', $this->
getPrice()),
425 'discount' => array(
'float', $this->
getDiscount()),
429 'voucher' => array(
'text', $this->
getVoucher()),
431 'street' => array(
'text', $this->
getStreet()),
432 'po_box' => array(
'text', $this->
getPoBox()),
433 'zipcode' => array(
'text', $this->
getZipcode()),
434 'city' => array(
'text', $this->
getCity()),
435 'country' => array(
'text', $this->
getCountry()),
436 'vat_rate' => array(
'float', $this->
getVatRate()),
438 'vat_unit' => array(
'float', $this->
getVatUnit()),
449 $statement = $this->db->insert(
'payment_statistic',
451 'booking_id' => array(
'integer', $next_id),
453 'pobject_id' => array(
'integer', $this->
getPobjectId()),
455 'b_vendor_id' => array(
'integer', $this->
getVendorId()),
456 'b_pay_method' => array(
'integer', $this->
getPayMethod()),
457 'order_date' => array(
'integer', $this->
getOrderDate()),
459 'price' => array(
'float', $this->
getPrice()),
460 'discount' => array(
'float', $this->
getDiscount()),
464 'voucher' => array(
'text', $this->
getVoucher()),
466 #
'street' => array(
'text', $this->
getStreet()),
467 #
'po_box' => array(
'text', $this->
getPoBox()),
468 #
'zipcode' => array(
'text', $this->
getZipcode()),
469 #
'city' => array(
'text', $this->
getCity()),
470 #
'country' => array(
'text', $this->
getCountry()),
471 'vat_rate' => array(
'float', $this->
getVatRate()),
473 'vat_unit' => array(
'float', $this->
getVatUnit()),
490 $statement = $this->db->manipulateF(
'
491 UPDATE payment_statistic
494 WHERE booking_id = %s',
495 array(
'integer',
'integer',
'integer'),
503 public function delete()
507 $statement = $this->db->manipulateF(
'
508 DELETE FROM payment_statistic WHERE booking_id = %s',
522 if(ANONYMOUS_USER_ID == $a_usr_id)
526 $res = $ilDB->queryf(
'
527 SELECT * from payment_statistic ps, payment_objects po
528 WHERE ps.pobject_id = po.pobject_id
530 ORDER BY order_date DESC',
535 while(
$row = $ilDB->fetchAssoc(
$res))
537 $booking[
$row[
'booking_id']] =
$row;
545 return $this->bookings ? $this->bookings : array();
550 $res = $this->db->queryf(
'
551 SELECT * FROM payment_statistic ps, payment_objects po
552 WHERE ps.pobject_id = po.pobject_id
553 AND booking_id = %s',
555 array($a_booking_id));
557 while(
$row = $this->db->fetchObject(
$res))
561 return $booking ? $booking : array();
569 $res = $ilDB->queryf(
570 'SELECT COUNT(booking_id) bid FROM payment_statistic
571 WHERE b_vendor_id = %s',
573 array($a_vendor_id));
575 while(
$row = $ilDB->fetchAssoc(
$res))
586 if(ANONYMOUS_USER_ID == $a_vendor_id)
589 $res = $ilDB->queryf(
'
590 SELECT COUNT(booking_id) bid FROM payment_statistic
591 WHERE customer_id = %s',
593 array($a_vendor_id));
595 while(
$row = $ilDB->fetchObject(
$res))
606 $res = $ilDB->queryf(
'
607 SELECT COUNT(booking_id) bid FROM payment_statistic
608 WHERE pobject_id = %s',
610 array($a_pobject_id));
612 while(
$row = $ilDB->fetchObject(
$res))
619 public static function _hasAccess($a_pobject_id, $a_user_id = 0, $a_transaction = 0)
621 global
$ilDB, $ilUser;
623 if(ANONYMOUS_USER_ID == $ilUser->getId() && !$a_transaction)
630 $res = $ilDB->queryf(
'
631 SELECT * FROM payment_statistic
632 WHERE pobject_id = %s
635 AND access_granted = %s',
636 array(
'integer',
'text',
'integer',
'integer'),
637 array($a_pobject_id, $a_transaction,
'1',
'1'));
641 $usr_id = $a_user_id ? $a_user_id : $ilUser->getId();
643 $res = $ilDB->queryf(
'
644 SELECT order_date, duration, access_enddate
645 FROM payment_statistic
646 WHERE pobject_id = %s
649 AND access_granted = %s',
650 array(
'integer',
'integer',
'integer',
'integer'),
651 array($a_pobject_id,
$usr_id,
'1',
'1'));
653 while(
$row = $ilDB->fetchObject(
$res))
655 if(
$row->duration != 0)
657 if( time() >=
$row->order_date
658 && date(
"Y-m-d") <=
$row->access_enddate)
670 global
$ilDB, $ilUser;
672 if(ANONYMOUS_USER_ID == $a_user_id)
674 $usr_id = $a_user_id ? $a_user_id : $ilUser->getId();
676 $res = $ilDB->queryf(
'
677 SELECT order_date, duration, access_enddate
678 FROM payment_statistic
679 WHERE pobject_id = %s
682 AND access_granted = %s',
683 array(
'integer',
'integer',
'integer',
'integer'),
684 array($a_pobject_id,
$usr_id,
'1',
'1'));
686 while(
$row = $ilDB->fetchObject(
$res))
688 if(
$row->duration != 0)
690 if( time() >=
$row->order_date
691 && date(
"Y-m-d") <=
$row->access_enddate)
694 "activation_start" =>
$row->order_date,
695 "activation_end" => mktime(0, 0, 0,
696 date(
'm',
$row->access_enddate),
697 date(
'd',
$row->access_enddate),
698 date(
'Y',
$row->access_enddate))
712 if(ANONYMOUS_USER_ID == $ilUser->getId())
716 $data_types = array();
718 $query =
'SELECT * FROM payment_statistic ps '
719 .
'INNER JOIN payment_objects po ON po.pobject_id = ps.pobject_id ';
720 if(
$_SESSION[
'pay_statistics'][
'customer'])
722 $query .=
'LEFT JOIN usr_data ud ON ud.usr_id = ps.customer_id ';
724 if(
$_SESSION[
'pay_statistics'][
'vendor'] && $this->admin_view)
726 $query .=
'LEFT JOIN usr_data udv ON udv.usr_id = ps.b_vendor_id ';
729 if (
$_SESSION[
'pay_statistics'][
'transaction_value'] !=
'')
731 if (
$_SESSION[
'pay_statistics'][
'transaction_type'] == 0)
733 $query .=
"AND transaction_extern LIKE %s ";
734 $data_types[] =
'text';
737 else if (
$_SESSION[
'pay_statistics'][
'transaction_type'] == 1)
739 $query .=
"AND transaction_extern LIKE %s ";
740 $data_types[] =
'text';
741 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'transaction_value'];
744 if (
$_SESSION[
'pay_statistics'][
'customer'] !=
'')
746 $query .=
"AND ud.login LIKE %s ";
747 $data_types[] =
'text';
748 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'customer'].
'%';
751 if (
$_SESSION[
'pay_statistics'][
'from'][
'date'][
'd'] !=
'' &&
752 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'm'] !=
'' &&
753 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'y'] !=
'')
756 $from = mktime(0, 0, 0,
$_SESSION[
'pay_statistics'][
'from'][
'date'][
'm'],
757 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'd'],
758 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'y']);
759 $query .=
'AND order_date >= %s ';
760 $data_types[] =
'integer';
763 if (
$_SESSION[
'pay_statistics'][
'til'][
'date'][
'd'] !=
'' &&
764 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'm'] !=
'' &&
765 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'y'] !=
'')
767 $til = mktime(23, 59, 59,
$_SESSION[
'pay_statistics'][
'til'][
'date'][
'm'],
768 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'd'],
769 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'y']);
770 $query .=
'AND order_date <= %s ';
771 $data_types[] =
'integer';
774 if (
$_SESSION[
'pay_statistics'][
'payed'] ==
'0' ||
775 $_SESSION[
'pay_statistics'][
'payed'] ==
'1')
777 $query .=
'AND payed = %s ';
778 $data_types[] =
'integer';
781 if (
$_SESSION[
'pay_statistics'][
'access'] ==
'0' ||
782 $_SESSION[
'pay_statistics'][
'access'] ==
'1')
784 $query .=
'AND access_granted = %s ';
785 $data_types[] =
'integer';
788 if (
$_SESSION[
'pay_statistics'][
'pay_method'] ==
'1' ||
789 $_SESSION[
'pay_statistics'][
'pay_method'] ==
'2' ||
790 $_SESSION[
'pay_statistics'][
'pay_method'] ==
'3')
792 $query .=
'AND b_pay_method = %s ';
793 $data_types[] =
'integer';
797 if(!$this->admin_view)
801 if (is_array($vendors) &&
804 $query .=
' AND '.$this->db->in(
'ps.b_vendor_id', $vendors,
false,
'integer').
' ';
806 else if(is_array($vendors) && count($vendors) == 1)
808 $query .=
'AND ps.b_vendor_id = %s ';
809 $data[] = $vendors[
'0'];
810 $data_types[] =
'integer';
812 if((
int)
$_SESSION[
'pay_statistics'][
'filter_title_id'])
814 $query .=
"AND po.ref_id = ".(int)$_SESSION[
'pay_statistics'][
'filter_title_id'].
" ";
819 if(
$_SESSION[
'pay_statistics'][
'vendor'])
821 $query .=
'AND udv.login LIKE %s ';
823 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'vendor'].
'%';
824 $data_types[] =
'text';
827 if((
int)
$_SESSION[
'pay_statistics'][
'adm_filter_title_id'])
829 $query .=
"AND po.ref_id = ".(int)
$_SESSION[
'pay_statistics'][
'adm_filter_title_id'].
" ";
832 $query .=
'ORDER BY order_date DESC';
834 $cnt_data = count(
$data);
835 $cnt_data_types = count($data_types);
837 if($cnt_data == 0 || $cnt_data_types == 0)
846 while(
$row = $this->db->fetchAssoc(
$res))
848 $this->bookings[
$row[
'booking_id']] =
$row;
872 return $vendors ? $vendors : array();
880 $query =
'SELECT * FROM payment_statistic as ps, payment_objects as po
881 WHERE ps.pobject_id = po.pobject_id
883 AND transaction = %s';
886 $res = $ilDB->queryF(
$query, array(
'integer',
'text'), array($a_user_id, $a_transaction_nr));
887 while(
$row = $ilDB->fetchAssoc(
$res))
899 $query =
'SELECT booking_id, order_date, customer_id, transaction FROM payment_statistic
900 WHERE customer_id = %s
901 GROUP BY transaction, order_date, booking_id, customer_id
902 ORDER BY order_date DESC
905 $res = $ilDB->queryF(
$query, array(
'integer'), array($a_user_id));
906 while(
$row = $ilDB->fetchAssoc(
$res))
908 $booking[
$row[
'booking_id']] =
$row;
910 return $booking ? $booking : array();
917 $res = $ilDB->queryF(
'
918 SELECT * FROM payment_statistic WHERE b_pay_method = %s', array(
'integer'), array(
$pay_method));
920 while(
$row = $ilDB->fetchAssoc(
$res))
924 return $booking ? $booking : array();
932 UPDATE payment_statistic
938 WHERE b_pay_method = %s',
947 $trans_exp = explode(
'_', $a_transaction);
950 $res = $ilDB->queryF(
'SELECT * FROM payment_statistic
951 WHERE transaction = %s
953 AND access_granted = %s
954 AND customer_id = %s',
955 array(
'text',
'integer',
'integer',
'integer'),
956 array($a_transaction, 1,1, (
int)
$user_id));
965 $query =
'SELECT DISTINCT(po.ref_id) ref_id FROM payment_statistic ps, payment_objects po';
966 $query .=
" WHERE ps.pobject_id = po.pobject_id ";
968 if(!$this->admin_view)
972 if (is_array($vendors) && count($vendors) > 1)
978 $data_types[] =
'integer';
980 $str_data = implode(
',',$arr_data);
982 $query .=
'AND ps.b_vendor_id IN ('.$str_data.
') ';
985 else if(is_array($vendors) && count($vendors) == 1)
987 $query .=
'AND ps.b_vendor_id = %s ';
988 $data[] = $vendors[
'0'];
989 $data_types[] =
'integer';
992 $query .=
"ORDER BY order_date DESC";
994 if(!$data_types && !
$data)
1003 $rows[] =
$row->ref_id;
1005 return is_array($rows) ? $rows : array();
1012 $res = $ilDB->queryF(
'SELECT * FROM payment_statistic
1013 WHERE customer_id = %s AND pobject_id = %s
1015 array(
'integer',
'integer',
'integer'),
1016 array($a_user_id, $a_pobject_id, 0));
1026 global $ilUser,
$ilDB;
1029 $res = $ilDB->queryF(
'
1030 SELECT order_date, duration
1031 FROM payment_statistic
1032 WHERE pobject_id = %s
1033 AND customer_id = %s
1034 ORDER BY order_date DESC',
1035 array(
'integer',
'integer'),
1036 array($a_pobject_id, $ilUser->getId()));
1038 while(
$row = $ilDB->fetchAssoc(
$res))