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)
403 include_once(
'Services/Calendar/classes/class.ilDateTime.php');
406 $start_date = $tmp_ts->getUnixTime();
409 $startDateYear = date(
"Y", $start_date);
410 $startDateMonth = date(
"m", $start_date);
411 $startDateDay = date(
"d", $start_date);
412 $startDateHour = date(
"H", $start_date);
413 $startDateMinute = date(
"i",$start_date);
414 $startDateSecond = date(
"s", $start_date);
416 $access_enddate = date(
"Y-m-d H:i:s", mktime($startDateHour, $startDateMinute, $startDateSecond,
417 $startDateMonth +
$duration, $startDateDay, $startDateYear));
424 include_once
'./Services/Payment/classes/class.ilPaymentPrices.php';
450 $next_id = $this->db->nextId(
'payment_statistic');
453 $statement = $this->db->insert(
'payment_statistic',
455 'booking_id' => array(
'integer', $next_id),
457 'pobject_id' => array(
'integer', $this->
getPobjectId()),
459 'b_vendor_id' => array(
'integer', $this->
getVendorId()),
460 'b_pay_method' => array(
'integer', $this->
getPayMethod()),
461 'order_date' => array(
'integer', $this->
getOrderDate()),
463 'price' => array(
'float', $this->
getPrice()),
464 'discount' => array(
'float', $this->
getDiscount()),
468 'voucher' => array(
'text', $this->
getVoucher()),
470 'street' => array(
'text', $this->
getStreet()),
471 'po_box' => array(
'text', $this->
getPoBox()),
472 'zipcode' => array(
'text', $this->
getZipcode()),
473 'city' => array(
'text', $this->
getCity()),
474 'country' => array(
'text', $this->
getCountry()),
475 'vat_rate' => array(
'float', $this->
getVatRate()),
477 'vat_unit' => array(
'float', $this->
getVatUnit()),
488 $statement = $this->db->insert(
'payment_statistic',
490 'booking_id' => array(
'integer', $next_id),
492 'pobject_id' => array(
'integer', $this->
getPobjectId()),
494 'b_vendor_id' => array(
'integer', $this->
getVendorId()),
495 'b_pay_method' => array(
'integer', $this->
getPayMethod()),
496 'order_date' => array(
'integer', $this->
getOrderDate()),
498 'price' => array(
'float', $this->
getPrice()),
499 'discount' => array(
'float', $this->
getDiscount()),
503 'voucher' => array(
'text', $this->
getVoucher()),
505 #
'street' => array(
'text', $this->
getStreet()),
506 #
'po_box' => array(
'text', $this->
getPoBox()),
507 #
'zipcode' => array(
'text', $this->
getZipcode()),
508 #
'city' => array(
'text', $this->
getCity()),
509 #
'country' => array(
'text', $this->
getCountry()),
510 'vat_rate' => array(
'float', $this->
getVatRate()),
512 'vat_unit' => array(
'float', $this->
getVatUnit()),
529 $statement = $this->db->manipulateF(
'
530 UPDATE payment_statistic
533 WHERE booking_id = %s',
534 array(
'integer',
'integer',
'integer'),
542 public function delete()
546 $statement = $this->db->manipulateF(
'
547 DELETE FROM payment_statistic WHERE booking_id = %s',
561 if(ANONYMOUS_USER_ID == $a_usr_id)
565 $res = $ilDB->queryf(
'
566 SELECT * from payment_statistic ps, payment_objects po
567 WHERE ps.pobject_id = po.pobject_id
569 ORDER BY order_date DESC',
574 while(
$row = $ilDB->fetchAssoc(
$res))
576 $booking[
$row[
'booking_id']] =
$row;
584 return $this->bookings ? $this->bookings : array();
590 $res = $this->db->queryf(
'
591 SELECT * FROM payment_statistic ps, payment_objects po
592 WHERE ps.pobject_id = po.pobject_id
593 AND booking_id = %s',
595 array($a_booking_id));
597 while(
$row = $this->db->fetchObject(
$res))
601 return $booking ? $booking : array();
609 $res = $ilDB->queryf(
610 'SELECT COUNT(booking_id) bid FROM payment_statistic
611 WHERE b_vendor_id = %s',
613 array($a_vendor_id));
615 while(
$row = $ilDB->fetchAssoc(
$res))
626 if(ANONYMOUS_USER_ID == $a_vendor_id)
629 $res = $ilDB->queryf(
'
630 SELECT COUNT(booking_id) bid FROM payment_statistic
631 WHERE customer_id = %s',
633 array($a_vendor_id));
635 while(
$row = $ilDB->fetchObject(
$res))
646 $res = $ilDB->queryf(
'
647 SELECT COUNT(booking_id) bid FROM payment_statistic
648 WHERE pobject_id = %s',
650 array($a_pobject_id));
652 while(
$row = $ilDB->fetchObject(
$res))
659 public static function _hasAccess($a_pobject_id, $a_user_id = 0, $a_transaction = 0)
663 if(ANONYMOUS_USER_ID == $ilUser->getId() && !$a_transaction)
670 $res = $ilDB->queryf(
'
671 SELECT * FROM payment_statistic
672 WHERE pobject_id = %s
675 AND access_granted = %s',
676 array(
'integer',
'text',
'integer',
'integer'),
677 array($a_pobject_id, $a_transaction,
'1',
'1'));
681 $usr_id = $a_user_id ? $a_user_id : $ilUser->getId();
683 $res = $ilDB->queryf(
'
684 SELECT order_date, duration, access_startdate, access_enddate
685 FROM payment_statistic
686 WHERE pobject_id = %s
689 AND access_granted = %s',
690 array(
'integer',
'integer',
'integer',
'integer'),
691 array($a_pobject_id,
$usr_id,
'1',
'1'));
694 while(
$row = $ilDB->fetchAssoc(
$res))
696 if(
$row[
'duration'] == 0 &&
$row[
'access_enddate'] == NULL)
701 if(
$row[
'access_startdate'] == NULL)
703 if(time() >=
$row[
'order_date']
704 && date(
"Y-m-d H:i:s") <=
$row[
'access_enddate'])
710 if (date(
"Y-m-d H:i:s") >=
$row[
'access_startdate']
711 && date(
"Y-m-d H:i:s") <=
$row[
'access_enddate'])
724 if(ANONYMOUS_USER_ID == $ilUser->getId())
728 $data_types = array();
730 $query =
'SELECT * FROM payment_statistic ps '
731 .
'INNER JOIN payment_objects po ON po.pobject_id = ps.pobject_id ';
732 if(
$_SESSION[
'pay_statistics'][
'customer'])
734 $query .=
'LEFT JOIN usr_data ud ON ud.usr_id = ps.customer_id ';
736 if(
$_SESSION[
'pay_statistics'][
'vendor'] && $this->admin_view)
738 $query .=
'LEFT JOIN usr_data udv ON udv.usr_id = ps.b_vendor_id ';
741 if (
$_SESSION[
'pay_statistics'][
'transaction_value'] !=
'')
743 if (
$_SESSION[
'pay_statistics'][
'transaction_type'] == 0)
745 $query .=
"AND transaction_extern LIKE %s ";
746 $data_types[] =
'text';
749 else if (
$_SESSION[
'pay_statistics'][
'transaction_type'] == 1)
751 $query .=
"AND transaction_extern LIKE %s ";
752 $data_types[] =
'text';
753 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'transaction_value'];
756 if (
$_SESSION[
'pay_statistics'][
'customer'] !=
'')
758 $query .=
"AND ud.login LIKE %s ";
759 $data_types[] =
'text';
760 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'customer'].
'%';
763 if (
$_SESSION[
'pay_statistics'][
'from'][
'date'][
'd'] !=
'' &&
764 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'm'] !=
'' &&
765 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'y'] !=
'')
768 $from = mktime(0, 0, 0,
$_SESSION[
'pay_statistics'][
'from'][
'date'][
'm'],
769 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'd'],
770 $_SESSION[
'pay_statistics'][
'from'][
'date'][
'y']);
771 $query .=
'AND order_date >= %s ';
772 $data_types[] =
'integer';
775 if (
$_SESSION[
'pay_statistics'][
'til'][
'date'][
'd'] !=
'' &&
776 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'm'] !=
'' &&
777 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'y'] !=
'')
779 $til = mktime(23, 59, 59,
$_SESSION[
'pay_statistics'][
'til'][
'date'][
'm'],
780 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'd'],
781 $_SESSION[
'pay_statistics'][
'til'][
'date'][
'y']);
782 $query .=
'AND order_date <= %s ';
783 $data_types[] =
'integer';
786 if (
$_SESSION[
'pay_statistics'][
'payed'] ==
'0' ||
787 $_SESSION[
'pay_statistics'][
'payed'] ==
'1')
789 $query .=
'AND payed = %s ';
790 $data_types[] =
'integer';
793 if (
$_SESSION[
'pay_statistics'][
'access'] ==
'0' ||
794 $_SESSION[
'pay_statistics'][
'access'] ==
'1')
796 $query .=
'AND access_granted = %s ';
797 $data_types[] =
'integer';
800 if (
$_SESSION[
'pay_statistics'][
'pay_method'] ==
'1' ||
801 $_SESSION[
'pay_statistics'][
'pay_method'] ==
'2' ||
802 $_SESSION[
'pay_statistics'][
'pay_method'] ==
'3')
804 $query .=
'AND b_pay_method = %s ';
805 $data_types[] =
'integer';
809 if(!$this->admin_view)
813 if (is_array($vendors) &&
816 $query .=
' AND '.$this->db->in(
'ps.b_vendor_id', $vendors,
false,
'integer').
' ';
818 else if(is_array($vendors) && count($vendors) == 1)
820 $query .=
'AND ps.b_vendor_id = %s ';
821 $data[] = $vendors[
'0'];
822 $data_types[] =
'integer';
824 if((
int)
$_SESSION[
'pay_statistics'][
'filter_title_id'])
826 $query .=
"AND po.ref_id = ".(int)$_SESSION[
'pay_statistics'][
'filter_title_id'].
" ";
831 if(
$_SESSION[
'pay_statistics'][
'vendor'])
833 $query .=
'AND udv.login LIKE %s ';
835 $data[] =
'%'.$_SESSION[
'pay_statistics'][
'vendor'].
'%';
836 $data_types[] =
'text';
839 if((
int)
$_SESSION[
'pay_statistics'][
'adm_filter_title_id'])
841 $query .=
"AND po.ref_id = ".(int)
$_SESSION[
'pay_statistics'][
'adm_filter_title_id'].
" ";
844 $query .=
'ORDER BY order_date DESC';
846 $cnt_data = count(
$data);
847 $cnt_data_types = count($data_types);
849 if($cnt_data == 0 || $cnt_data_types == 0)
858 while(
$row = $this->db->fetchAssoc(
$res))
860 $this->bookings[
$row[
'booking_id']] =
$row;
867 if(ilPaymentVendors::_isVendor($this->user_id))
884 return $vendors ? $vendors : array();
892 $query =
'SELECT * FROM payment_statistic as ps, payment_objects as po
893 WHERE ps.pobject_id = po.pobject_id
895 AND transaction = %s';
897 $res = $ilDB->queryF(
$query, array(
'integer',
'text'), array($a_user_id, $a_transaction_nr));
898 while(
$row = $ilDB->fetchAssoc(
$res))
910 $query =
'SELECT * FROM payment_statistic
911 WHERE customer_id = %s
913 ORDER BY order_date DESC';
915 $res = $ilDB->queryF(
$query, array(
'integer'), array($a_user_id));
916 while(
$row = $ilDB->fetchAssoc(
$res))
918 $booking[
$row[
'booking_id']] =
$row;
920 return $booking ? $booking : array();
927 $res = $ilDB->queryF(
'
928 SELECT * FROM payment_statistic WHERE b_pay_method = %s', array(
'integer'), array(
$pay_method));
930 while(
$row = $ilDB->fetchAssoc(
$res))
934 return $booking ? $booking : array();
942 UPDATE payment_statistic
948 WHERE b_pay_method = %s',
957 $trans_exp = explode(
'_', $a_transaction);
960 $res = $ilDB->queryF(
'SELECT * FROM payment_statistic
961 WHERE transaction = %s
963 AND access_granted = %s
964 AND customer_id = %s',
965 array(
'text',
'integer',
'integer',
'integer'),
966 array($a_transaction, 1,1, (
int)
$user_id));
976 $query =
'SELECT DISTINCT(po.ref_id) ref_id FROM payment_statistic ps, payment_objects po';
977 $query .=
" WHERE ps.pobject_id = po.pobject_id ";
979 if(!$this->admin_view)
983 if (is_array($vendors) && count($vendors) > 1)
985 foreach($vendors as $vendor)
989 $data_types[] =
'integer';
991 $str_data = implode(
',',$arr_data);
993 $query .=
'AND ps.b_vendor_id IN ('.$str_data.
') ';
996 else if(is_array($vendors) && count($vendors) == 1)
998 $query .=
'AND ps.b_vendor_id = %s ';
999 $data[] = $vendors[
'0'];
1000 $data_types[] =
'integer';
1003 $query .=
"ORDER BY order_date DESC";
1005 if(!$data_types && !
$data)
1014 $rows[] =
$row->ref_id;
1016 return is_array($rows) ? $rows : array();
1023 $res = $ilDB->queryF(
'SELECT * FROM payment_statistic
1024 WHERE customer_id = %s AND pobject_id = %s
1026 array(
'integer',
'integer',
'integer'),
1027 array($a_user_id, $a_pobject_id, 0));
1040 $res = $ilDB->queryF(
'
1041 SELECT order_date, duration
1042 FROM payment_statistic
1043 WHERE pobject_id = %s
1044 AND customer_id = %s
1045 ORDER BY order_date DESC',
1046 array(
'integer',
'integer'),
1047 array($a_pobject_id, $ilUser->getId()));
1049 while(
$row = $ilDB->fetchAssoc(
$res))