11 include_once
'./Services/Payment/classes/class.ilPaymentVendors.php';
12 include_once
'./Services/Payment/classes/class.ilPaymentTrustees.php';
62 public function __construct($a_user_id =
'',$a_admin_view =
false)
66 $this->admin_view = $a_admin_view;
67 $this->user_id = $a_user_id;
70 include_once
'./Services/Payment/classes/class.ilPaymentSettings.php';
72 $this->currency_unit = $genSet->get(
'currency_unit');
83 return $this->booking_id = $a_booking_id;
91 $this->transaction = $a_transaction;
99 $this->pobject_id = $a_pobject_id;
107 $this->customer_id = $a_customer_id;
115 $this->vendor_id = $a_vendor_id;
123 $this->pay_method = $a_pay_method;
131 $this->order_date = $a_order_date;
139 $this->duration = $a_duration;
147 if($a_unlimited_duration ==
'' || null) $a_unlimited_duration = 0;
148 $this->unlimited_duration = $a_unlimited_duration;
158 $this->price_type = $a_price_type;
167 $this->price = $a_price;
175 if($a_discount == null) $a_discount = 0;
176 $this->discount = $a_discount;
180 if($this->discount == null) $this->discount = 0;
185 $this->payed = $a_payed;
193 $this->access = $a_access;
201 $this->voucher = $a_voucher;
209 $this->transaction_extern = $a_transaction_extern;
222 $street = $a_street.
' '.$a_house_nr;
231 $this->po_box = $a_po_box;
240 $this->zipcode = $a_zipcode;
248 $this->city = $a_city;
257 $this->country = $a_country;
262 $this->vat_unit = $a_vat_unit;
271 $this->vat_rate = $a_vat_rate;
275 return $this->vat_rate;
279 $this->object_title = $a_object_title;
288 $this->email_extern = $a_email_extern;
297 $this->name_extern = $a_name_extern;
305 $this->currency_unit = $a_currency_unit;
314 $this->access_startdate = $a_access_startdate;
323 $this->access_enddate = $a_access_enddate;
332 $this->access_extension = $a_access_extension;
343 $ilDB->setLimit(1,0);
346 $res_1 = $ilDB->queryF(
'SELECT * FROM payment_statistic
347 WHERE pobject_id = %s
350 AND access_enddate = %s',
351 array(
'integer',
'integer',
'integer',
'timestamp'),
355 $row_1 = $ilDB->fetchAssoc($res_1);
356 if(count($row_1) > 0 )
363 $res_2 = $ilDB->queryF(
'SELECT * FROM payment_statistic
364 WHERE pobject_id = %s
366 ORDER BY access_enddate DESC',
367 array(
'integer',
'integer'),
371 $row_2 = $ilDB->fetchAssoc($res_2);
372 if(count($row_2) > 0)
376 $old_enddate = $row_2[
'access_enddate']; # Y-m-d H:i:s
377 $current_date = date(
"Y-m-d H:i:s", $this->
getOrderDate());
379 if($old_enddate <= $current_date)
402 include_once(
'Services/Calendar/classes/class.ilDateTime.php');
405 $start_date = $tmp_ts->getUnixTime();
408 $startDateYear = date(
"Y", $start_date);
409 $startDateMonth = date(
"m", $start_date);
410 $startDateDay = date(
"d", $start_date);
411 $startDateHour = date(
"H", $start_date);
412 $startDateMinute = date(
"i",$start_date);
413 $startDateSecond = date(
"s", $start_date);
415 $access_enddate = date(
"Y-m-d H:i:s", mktime($startDateHour, $startDateMinute, $startDateSecond,
416 $startDateMonth +
$duration, $startDateDay, $startDateYear));
423 include_once
'./Services/Payment/classes/class.ilPaymentPrices.php';
449 $next_id = $this->db->nextId(
'payment_statistic');
452 $this->db->insert(
'payment_statistic',
454 'booking_id' => array(
'integer', $next_id),
456 'pobject_id' => array(
'integer', $this->
getPobjectId()),
458 'b_vendor_id' => array(
'integer', $this->
getVendorId()),
459 'b_pay_method' => array(
'integer', $this->
getPayMethod()),
460 'order_date' => array(
'integer', $this->
getOrderDate()),
462 'price' => array(
'float', $this->
getPrice()),
463 'discount' => array(
'float', $this->
getDiscount()),
467 'voucher' => array(
'text', $this->
getVoucher()),
469 'street' => array(
'text', $this->
getStreet()),
470 'po_box' => array(
'text', $this->
getPoBox()),
471 'zipcode' => array(
'text', $this->
getZipcode()),
472 'city' => array(
'text', $this->
getCity()),
473 'country' => array(
'text', $this->
getCountry()),
474 'vat_rate' => array(
'float', $this->
getVatRate()),
476 'vat_unit' => array(
'float', $this->
getVatUnit()),
487 $this->db->insert(
'payment_statistic',
489 'booking_id' => array(
'integer', $next_id),
491 'pobject_id' => array(
'integer', $this->
getPobjectId()),
493 'b_vendor_id' => array(
'integer', $this->
getVendorId()),
494 'b_pay_method' => array(
'integer', $this->
getPayMethod()),
495 'order_date' => array(
'integer', $this->
getOrderDate()),
497 'price' => array(
'float', $this->
getPrice()),
498 'discount' => array(
'float', $this->
getDiscount()),
502 'voucher' => array(
'text', $this->
getVoucher()),
504 #
'street' => array(
'text', $this->
getStreet()),
505 #
'po_box' => array(
'text', $this->
getPoBox()),
506 #
'zipcode' => array(
'text', $this->
getZipcode()),
507 #
'city' => array(
'text', $this->
getCity()),
508 #
'country' => array(
'text', $this->
getCountry()),
509 'vat_rate' => array(
'float', $this->
getVatRate()),
511 'vat_unit' => array(
'float', $this->
getVatUnit()),
528 $this->db->manipulateF(
'
529 UPDATE payment_statistic
532 WHERE booking_id = %s',
533 array(
'integer',
'integer',
'integer'),
541 public function delete()
545 $this->db->manipulateF(
'
546 DELETE FROM payment_statistic WHERE booking_id = %s',
560 if(ANONYMOUS_USER_ID == $a_usr_id)
564 $res = $ilDB->queryf(
'
565 SELECT * from payment_statistic ps, payment_objects po
566 WHERE ps.pobject_id = po.pobject_id
568 ORDER BY order_date DESC',
573 while(
$row = $ilDB->fetchAssoc(
$res))
575 $booking[
$row[
'booking_id']] =
$row;
583 return $this->bookings ? $this->bookings : array();
589 $res = $this->db->queryf(
'
590 SELECT * FROM payment_statistic ps, payment_objects po
591 WHERE ps.pobject_id = po.pobject_id
592 AND booking_id = %s',
594 array($a_booking_id));
596 while(
$row = $this->db->fetchObject(
$res))
600 return $booking ? $booking : array();
608 $res = $ilDB->queryf(
609 'SELECT COUNT(booking_id) bid FROM payment_statistic
610 WHERE b_vendor_id = %s',
612 array($a_vendor_id));
614 while(
$row = $ilDB->fetchAssoc(
$res))
625 if(ANONYMOUS_USER_ID == $a_vendor_id)
628 $res = $ilDB->queryf(
'
629 SELECT COUNT(booking_id) bid FROM payment_statistic
630 WHERE customer_id = %s',
632 array($a_vendor_id));
634 while(
$row = $ilDB->fetchObject(
$res))
645 $res = $ilDB->queryf(
'
646 SELECT COUNT(booking_id) bid FROM payment_statistic
647 WHERE pobject_id = %s',
649 array($a_pobject_id));
651 while(
$row = $ilDB->fetchObject(
$res))
658 public static function _hasAccess($a_pobject_id, $a_user_id = 0, $a_transaction = 0)
662 if(ANONYMOUS_USER_ID == $ilUser->getId() && !$a_transaction)
669 $res = $ilDB->queryf(
'
670 SELECT * FROM payment_statistic
671 WHERE pobject_id = %s
674 AND access_granted = %s',
675 array(
'integer',
'text',
'integer',
'integer'),
676 array($a_pobject_id, $a_transaction,
'1',
'1'));
680 $usr_id = $a_user_id ? $a_user_id : $ilUser->getId();
682 $res = $ilDB->queryf(
'
683 SELECT order_date, duration, access_startdate, access_enddate
684 FROM payment_statistic
685 WHERE pobject_id = %s
688 AND access_granted = %s',
689 array(
'integer',
'integer',
'integer',
'integer'),
690 array($a_pobject_id, $usr_id,
'1',
'1'));
693 while(
$row = $ilDB->fetchAssoc(
$res))
695 if(
$row[
'duration'] == 0 &&
$row[
'access_enddate'] == NULL)
700 if(
$row[
'access_startdate'] == NULL)
702 if(time() >=
$row[
'order_date']
703 && date(
"Y-m-d H:i:s") <=
$row[
'access_enddate'])
709 if (date(
"Y-m-d H:i:s") >=
$row[
'access_startdate']
710 && date(
"Y-m-d H:i:s") <=
$row[
'access_enddate'])
723 if(ANONYMOUS_USER_ID == $ilUser->getId())
727 $data_types = array();
729 $query =
'SELECT * FROM payment_statistic ps '
730 .
'INNER JOIN payment_objects po ON po.pobject_id = ps.pobject_id ';
731 if(
$_SESSION[
'pay_statistics'][
'customer'])
733 $query .=
'LEFT JOIN usr_data ud ON ud.usr_id = ps.customer_id ';
735 if(
$_SESSION[
'pay_statistics'][
'vendor'] && $this->admin_view)
737 $query .=
'LEFT JOIN usr_data udv ON udv.usr_id = ps.b_vendor_id ';
740 if (
$_SESSION[
'pay_statistics'][
'transaction_value'] !=
'')
742 if (
$_SESSION[
'pay_statistics'][
'transaction_type'] == 0)
744 $query .=
"AND transaction_extern LIKE %s ";
745 $data_types[] =
'text';
746 $data[] =
$_SESSION[
'pay_statistics'][
'transaction_value'].
'%';
748 else if (
$_SESSION[
'pay_statistics'][
'transaction_type'] == 1)
750 $query .=
"AND transaction_extern LIKE %s ";
751 $data_types[] =
'text';
752 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'transaction_value'];
755 if (
$_SESSION[
'pay_statistics'][
'customer'] !=
'')
757 $query .=
"AND ud.login LIKE %s ";
758 $data_types[] =
'text';
759 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'customer'].
'%';
762 if (
$_SESSION[
'pay_statistics'][
'from'][
'date'][
'd'] !=
'' &&
763 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'm'] !=
'' &&
764 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'y'] !=
'')
767 $from = mktime(0, 0, 0,
$_SESSION[
'pay_statistics'][
'from'][
'date'][
'm'],
768 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'd'],
769 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'y']);
770 $query .=
'AND order_date >= %s ';
771 $data_types[] =
'integer';
774 if (
$_SESSION[
'pay_statistics'][
'til'][
'date'][
'd'] !=
'' &&
775 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'm'] !=
'' &&
776 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'y'] !=
'')
778 $til = mktime(23, 59, 59,
$_SESSION[
'pay_statistics'][
'til'][
'date'][
'm'],
779 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'd'],
780 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'y']);
781 $query .=
'AND order_date <= %s ';
782 $data_types[] =
'integer';
785 if (
$_SESSION[
'pay_statistics'][
'payed'] ==
'0' ||
786 $_SESSION[
'pay_statistics'][
'payed'] ==
'1')
788 $query .=
'AND payed = %s ';
789 $data_types[] =
'integer';
790 $data[] =
$_SESSION[
'pay_statistics'][
'payed'];
792 if (
$_SESSION[
'pay_statistics'][
'access'] ==
'0' ||
793 $_SESSION[
'pay_statistics'][
'access'] ==
'1')
795 $query .=
'AND access_granted = %s ';
796 $data_types[] =
'integer';
797 $data[] =
$_SESSION[
'pay_statistics'][
'access'];
799 if (
$_SESSION[
'pay_statistics'][
'pay_method'] ==
'1' ||
800 $_SESSION[
'pay_statistics'][
'pay_method'] ==
'2' ||
801 $_SESSION[
'pay_statistics'][
'pay_method'] ==
'3')
803 $query .=
'AND b_pay_method = %s ';
804 $data_types[] =
'integer';
805 $data[] =
$_SESSION[
'pay_statistics'][
'pay_method'];
808 if(!$this->admin_view)
812 if (is_array($vendors) &&
815 $query .=
' AND '.$this->db->in(
'ps.b_vendor_id', $vendors,
false,
'integer').
' ';
817 else if(is_array($vendors) && count($vendors) == 1)
819 $query .=
'AND ps.b_vendor_id = %s ';
820 $data[] = $vendors[
'0'];
821 $data_types[] =
'integer';
823 if((
int)
$_SESSION[
'pay_statistics'][
'filter_title_id'])
825 $query .=
"AND po.ref_id = ".(int)$_SESSION[
'pay_statistics'][
'filter_title_id'].
" ";
830 if(
$_SESSION[
'pay_statistics'][
'vendor'])
832 $query .=
'AND udv.login LIKE %s ';
834 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'vendor'].
'%';
835 $data_types[] =
'text';
838 if((
int)
$_SESSION[
'pay_statistics'][
'adm_filter_title_id'])
840 $query .=
"AND po.ref_id = ".(int)
$_SESSION[
'pay_statistics'][
'adm_filter_title_id'].
" ";
843 $query .=
'ORDER BY order_date DESC';
845 $cnt_data = count($data);
846 $cnt_data_types = count($data_types);
848 if($cnt_data == 0 || $cnt_data_types == 0)
854 $res= $this->db->queryf(
$query, $data_types, $data);
857 while(
$row = $this->db->fetchAssoc(
$res))
859 $this->bookings[
$row[
'booking_id']] =
$row;
866 if(ilPaymentVendors::_isVendor($this->user_id))
883 return $vendors ? $vendors : array();
891 $query =
'SELECT * FROM payment_statistic as ps, payment_objects as po
892 WHERE ps.pobject_id = po.pobject_id
894 AND transaction = %s';
896 $res = $ilDB->queryF(
$query, array(
'integer',
'text'), array($a_user_id, $a_transaction_nr));
897 while(
$row = $ilDB->fetchAssoc(
$res))
909 $query =
'SELECT * FROM payment_statistic
910 WHERE customer_id = %s
912 ORDER BY order_date DESC';
914 $res = $ilDB->queryF(
$query, array(
'integer'), array($a_user_id));
915 while(
$row = $ilDB->fetchAssoc(
$res))
917 $booking[
$row[
'booking_id']] =
$row;
919 return $booking ? $booking : array();
926 $res = $ilDB->queryF(
'
927 SELECT * FROM payment_statistic WHERE b_pay_method = %s', array(
'integer'), array(
$pay_method));
929 while(
$row = $ilDB->fetchAssoc(
$res))
933 return $booking ? $booking : array();
941 UPDATE payment_statistic
947 WHERE b_pay_method = %s',
956 $trans_exp = explode(
'_', $a_transaction);
959 $res = $ilDB->queryF(
'SELECT * FROM payment_statistic
960 WHERE transaction = %s
962 AND access_granted = %s
963 AND customer_id = %s',
964 array(
'text',
'integer',
'integer',
'integer'),
965 array($a_transaction, 1,1, (
int)
$user_id));
975 $query =
'SELECT DISTINCT(po.ref_id) ref_id FROM payment_statistic ps, payment_objects po';
976 $query .=
" WHERE ps.pobject_id = po.pobject_id ";
978 if(!$this->admin_view)
982 if (is_array($vendors) && count($vendors) > 1)
984 foreach($vendors as $vendor)
988 $data_types[] =
'integer';
990 $str_data = implode(
',',$arr_data);
992 $query .=
'AND ps.b_vendor_id IN ('.$str_data.
') ';
995 else if(is_array($vendors) && count($vendors) == 1)
997 $query .=
'AND ps.b_vendor_id = %s ';
998 $data[] = $vendors[
'0'];
999 $data_types[] =
'integer';
1002 $query .=
"ORDER BY order_date DESC";
1004 if(!$data_types && !$data)
1008 else $res = $this->db->queryf(
$query, $data_types, $data);
1013 $rows[] =
$row->ref_id;
1015 return is_array($rows) ? $rows : array();
1022 $res = $ilDB->queryF(
'SELECT * FROM payment_statistic
1023 WHERE customer_id = %s AND pobject_id = %s
1025 array(
'integer',
'integer',
'integer'),
1026 array($a_user_id, $a_pobject_id, 0));
1039 $res = $ilDB->queryF(
'
1040 SELECT order_date, duration
1041 FROM payment_statistic
1042 WHERE pobject_id = %s
1043 AND customer_id = %s
1044 ORDER BY order_date DESC',
1045 array(
'integer',
'integer'),
1046 array($a_pobject_id, $ilUser->getId()));
1048 while(
$row = $ilDB->fetchAssoc(
$res))