00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00032 include_once './payment/classes/class.ilPaymentObject.php';
00033
00034 class ilPaymentStatisticGUI extends ilPaymentBaseGUI
00035 {
00036 var $ctrl;
00037
00038 var $lng;
00039 var $user_obj;
00040 var $pobject = null;
00041
00042 function ilPaymentStatisticGUI(&$user_obj)
00043 {
00044 global $ilCtrl;
00045
00046 $this->ctrl =& $ilCtrl;
00047
00048 $this->ilPaymentBaseGUI();
00049
00050 $this->user_obj =& $user_obj;
00051
00052 $this->pobject =& new ilPaymentObject($this->user_obj);
00053
00054 }
00058 function &executeCommand()
00059 {
00060 global $tree;
00061
00062 $cmd = $this->ctrl->getCmd();
00063 switch ($this->ctrl->getNextClass($this))
00064 {
00065 default:
00066 if(!$cmd = $this->ctrl->getCmd())
00067 {
00068 $cmd = 'showStatistics';
00069 }
00070 $this->$cmd();
00071 break;
00072 }
00073 }
00074
00075 function resetFilter()
00076 {
00077 unset($_SESSION["pay_statistics"]);
00078 unset($_POST["transaction_type"]);
00079 unset($_POST["transaction_value"]);
00080 unset($_POST["from"]["day"]);
00081 unset($_POST["from"]["month"]);
00082 unset($_POST["from"]["year"]);
00083 unset($_POST["til"]["day"]);
00084 unset($_POST["til"]["month"]);
00085 unset($_POST["til"]["year"]);
00086 unset($_POST["payed"]);
00087 unset($_POST["access"]);
00088 unset($_POST["customer"]);
00089 $this->showStatistics();
00090 }
00091
00092 function showStatistics()
00093 {
00094 if ($_POST["updateView"] == 1)
00095 {
00096 $_SESSION["pay_statistics"]["transaction_type"] = $_POST["transaction_type"];
00097 $_SESSION["pay_statistics"]["transaction_value"] = $_POST["transaction_value"];
00098 $_SESSION["pay_statistics"]["from"]["day"] = $_POST["from"]["day"];
00099 $_SESSION["pay_statistics"]["from"]["month"] = $_POST["from"]["month"];
00100 $_SESSION["pay_statistics"]["from"]["year"] = $_POST["from"]["year"];
00101 $_SESSION["pay_statistics"]["til"]["day"] = $_POST["til"]["day"];
00102 $_SESSION["pay_statistics"]["til"]["month"] = $_POST["til"]["month"];
00103 $_SESSION["pay_statistics"]["til"]["year"] = $_POST["til"]["year"];
00104 $_SESSION["pay_statistics"]["payed"] = $_POST["payed"];
00105 $_SESSION["pay_statistics"]["access"] = $_POST["access"];
00106 $_SESSION["pay_statistics"]["customer"] = $_POST["customer"];
00107 }
00108
00109 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_statistic.html',true);
00110
00111 $this->tpl->setVariable("TXT_FILTER",$this->lng->txt('pay_filter'));
00112 $this->tpl->setVariable("FORM_ACTION",$this->ctrl->getFormAction($this));
00113 $this->tpl->setVariable("TXT_TRANSACTION",$this->lng->txt('paya_transaction'));
00114 $this->tpl->setVariable("TXT_STARTING",$this->lng->txt('pay_starting'));
00115 $this->tpl->setVariable("TXT_ENDING",$this->lng->txt('pay_ending'));
00116 $this->tpl->setVariable("TXT_PAYED",$this->lng->txt('paya_payed'));
00117 $this->tpl->setVariable("TXT_ALL",$this->lng->txt('pay_all'));
00118 $this->tpl->setVariable("TXT_YES",$this->lng->txt('yes'));
00119 $this->tpl->setVariable("TXT_NO",$this->lng->txt('no'));
00120 $this->tpl->setVariable("TXT_CUSTOMER",$this->lng->txt('paya_customer'));
00121 $this->tpl->setVariable("TXT_ACCESS",$this->lng->txt('paya_access'));
00122 $this->tpl->setVariable("TXT_ORDER_DATE_FROM",$this->lng->txt('pay_order_date_from'));
00123 $this->tpl->setVariable("TXT_ORDER_DATE_TIL",$this->lng->txt('pay_order_date_til'));
00124 $this->tpl->setVariable("TXT_UPDATE_VIEW",$this->lng->txt('pay_update_view'));
00125 $this->tpl->setVariable("TXT_RESET_FILTER",$this->lng->txt('pay_reset_filter'));
00126
00127 $this->tpl->setVariable("TRANSACTION_TYPE_" . $_SESSION["pay_statistics"]["transaction_type"], " selected");
00128 $this->tpl->setVariable("TRANSACTION_VALUE", ilUtil::prepareFormOutput($_SESSION["pay_statistics"]["transaction_value"], true));
00129 $this->tpl->setVariable("PAYED_" . $_SESSION["pay_statistics"]["payed"], " selected");
00130 $this->tpl->setVariable("ACCESS_" . $_SESSION["pay_statistics"]["access"], " selected");
00131 $this->tpl->setVariable("CUSTOMER", ilUtil::prepareFormOutput($_SESSION["pay_statistics"]["customer"], true));
00132 for ($i = 1; $i <= 31; $i++)
00133 {
00134 $this->tpl->setCurrentBlock("loop_from_day");
00135 $this->tpl->setVariable("LOOP_FROM_DAY", $i < 10 ? "0" . $i : $i);
00136 if ($_SESSION["pay_statistics"]["from"]["day"] == $i)
00137 {
00138 $this->tpl->setVariable("LOOP_FROM_DAY_SELECTED", " selected");
00139 }
00140 $this->tpl->parseCurrentBlock("loop_from_day");
00141 $this->tpl->setCurrentBlock("loop_til_day");
00142 $this->tpl->setVariable("LOOP_TIL_DAY", $i < 10 ? "0" . $i : $i);
00143 if ($_SESSION["pay_statistics"]["til"]["day"] == $i)
00144 {
00145 $this->tpl->setVariable("LOOP_TIL_DAY_SELECTED", " selected");
00146 }
00147 $this->tpl->parseCurrentBlock("loop_til_day");
00148 }
00149 for ($i = 1; $i <= 12; $i++)
00150 {
00151 $this->tpl->setCurrentBlock("loop_from_month");
00152 $this->tpl->setVariable("LOOP_FROM_MONTH", $i < 10 ? "0" . $i : $i);
00153 if ($_SESSION["pay_statistics"]["from"]["month"] == $i)
00154 {
00155 $this->tpl->setVariable("LOOP_FROM_MONTH_SELECTED", " selected");
00156 }
00157 $this->tpl->parseCurrentBlock("loop_from_month");
00158 $this->tpl->setCurrentBlock("loop_til_month");
00159 $this->tpl->setVariable("LOOP_TIL_MONTH", $i < 10 ? "0" . $i : $i);
00160 if ($_SESSION["pay_statistics"]["til"]["month"] == $i)
00161 {
00162 $this->tpl->setVariable("LOOP_TIL_MONTH_SELECTED", " selected");
00163 }
00164 $this->tpl->parseCurrentBlock("loop_til_month");
00165 }
00166 for ($i = 2004; $i <= date("Y"); $i++)
00167 {
00168 $this->tpl->setCurrentBlock("loop_from_year");
00169 $this->tpl->setVariable("LOOP_FROM_YEAR", $i);
00170 if ($_SESSION["pay_statistics"]["from"]["year"] == $i)
00171 {
00172 $this->tpl->setVariable("LOOP_FROM_YEAR_SELECTED", " selected");
00173 }
00174 $this->tpl->parseCurrentBlock("loop_from_year");
00175 $this->tpl->setCurrentBlock("loop_til_year");
00176 $this->tpl->setVariable("LOOP_TIL_YEAR", $i);
00177 if ($_SESSION["pay_statistics"]["til"]["year"] == $i)
00178 {
00179 $this->tpl->setVariable("LOOP_TIL_YEAR_SELECTED", " selected");
00180 }
00181 $this->tpl->parseCurrentBlock("loop_til_year");
00182 }
00183
00184 $this->__initBookingObject();
00185
00186 if(!count($bookings = $this->booking_obj->getBookings()))
00187 {
00188 sendInfo($this->lng->txt('paya_no_bookings'));
00189
00190 return true;
00191 }
00192 $this->__showButton('excelExport',$this->lng->txt('excel_export'));
00193
00194 $img_change = "<img src=\"".ilUtil::getImagePath("edit.gif")."\" alt=\"".
00195 $this->lng->txt("edit")."\" title=\"".$this->lng->txt("edit").
00196 "\" border=\"0\" vspace=\"0\"/>";
00197
00198 $counter = 0;
00199 foreach($bookings as $booking)
00200 {
00201 $tmp_obj =& ilObjectFactory::getInstanceByRefId($booking['ref_id']);
00202 $tmp_vendor =& ilObjectFactory::getInstanceByObjId($booking['b_vendor_id']);
00203 $tmp_purchaser =& ilObjectFactory::getInstanceByObjId($booking['customer_id']);
00204
00205 $f_result[$counter][] = $booking['transaction_extern'];
00206 $f_result[$counter][] = $tmp_obj->getTitle();
00207 $f_result[$counter][] = '['.$tmp_vendor->getLogin().']';
00208 $f_result[$counter][] = '['.$tmp_purchaser->getLogin().']';
00209 $f_result[$counter][] = date('Y m d H:i:s',$booking['order_date']);
00210 $f_result[$counter][] = $booking['duration'];
00211 $f_result[$counter][] = $booking['price'];
00212
00213 $payed_access = $booking['payed'] ?
00214 $this->lng->txt('yes') :
00215 $this->lng->txt('no');
00216
00217 $payed_access .= '/';
00218 $payed_access .= $booking['access'] ?
00219 $this->lng->txt('yes') :
00220 $this->lng->txt('no');
00221
00222 $f_result[$counter][] = $payed_access;
00223
00224 $this->ctrl->setParameter($this,"booking_id",$booking['booking_id']);
00225 $link_change = "<a href=\"".$this->ctrl->getLinkTarget($this,"editStatistic")."\"> ".
00226 $img_change."</a>";
00227
00228 $f_result[$counter][] = $link_change;
00229
00230 unset($tmp_obj);
00231 unset($tmp_vendor);
00232 unset($tmp_purchaser);
00233
00234 ++$counter;
00235 }
00236 return $this->__showStatisticTable($f_result);
00237
00238 }
00239
00240 function excelExport()
00241 {
00242 include_once './payment/classes/class.ilPaymentExcelWriterAdapter.php';
00243
00244 $pewa =& new ilPaymentExcelWriterAdapter('payment_vendors.xls');
00245
00246
00247 $this->addStatisticWorksheet($pewa);
00248
00249
00250
00251 $workbook =& $pewa->getWorkbook();
00252 $workbook->close();
00253 }
00254
00255 function addStatisticWorksheet(&$pewa)
00256 {
00257 include_once './payment/classes/class.ilPaymentVendors.php';
00258
00259 $this->__initBookingObject();
00260
00261 if(!count($bookings = $this->booking_obj->getBookings()))
00262 {
00263 return false;
00264 }
00265
00266 $workbook =& $pewa->getWorkbook();
00267 $worksheet =& $workbook->addWorksheet($this->lng->txt('paya_statistic'));
00268
00269 $worksheet->mergeCells(0,0,0,8);
00270 $worksheet->setColumn(0,0,32);
00271 $worksheet->setColumn(0,1,32);
00272 $worksheet->setColumn(0,2,16);
00273 $worksheet->setColumn(0,3,16);
00274 $worksheet->setColumn(0,4,16);
00275 $worksheet->setColumn(0,5,24);
00276 $worksheet->setColumn(0,6,8);
00277 $worksheet->setColumn(0,7,12);
00278 $worksheet->setColumn(0,8,16);
00279
00280 $title = $this->lng->txt('paya_statistic');
00281 $title .= ' '.$this->lng->txt('as_of');
00282 $title .= strftime('%Y-%m-%d %R',time());
00283
00284 $worksheet->writeString(0,0,$title,$pewa->getFormatTitle());
00285
00286 $worksheet->writeString(1,0,$this->lng->txt('paya_transaction'),$pewa->getFormatHeader());
00287 $worksheet->writeString(1,1,$this->lng->txt('title'),$pewa->getFormatHeader());
00288 $worksheet->writeString(1,2,$this->lng->txt('paya_vendor'),$pewa->getFormatHeader());
00289 $worksheet->writeString(1,3,$this->lng->txt('pays_cost_center'),$pewa->getFormatHeader());
00290 $worksheet->writeString(1,4,$this->lng->txt('paya_customer'),$pewa->getFormatHeader());
00291 $worksheet->writeString(1,5,$this->lng->txt('paya_order_date'),$pewa->getFormatHeader());
00292 $worksheet->writeString(1,6,$this->lng->txt('duration'),$pewa->getFormatHeader());
00293 $worksheet->writeString(1,7,$this->lng->txt('price_a'),$pewa->getFormatHeader());
00294 $worksheet->writeString(1,8,$this->lng->txt('paya_payed_access'),$pewa->getFormatHeader());
00295
00296 $counter = 2;
00297 foreach($bookings as $booking)
00298 {
00299 $tmp_obj =& ilObjectFactory::getInstanceByRefId($booking['ref_id']);
00300 $tmp_vendor =& ilObjectFactory::getInstanceByObjId($booking['b_vendor_id']);
00301 $tmp_purchaser =& ilObjectFactory::getInstanceByObjId($booking['customer_id']);
00302
00303 $worksheet->writeString($counter,0,$booking['transaction_extern']);
00304 $worksheet->writeString($counter,1,$tmp_obj->getTitle());
00305 $worksheet->writeString($counter,2,$tmp_vendor->getLogin());
00306 $worksheet->writeString($counter,3,ilPaymentVendors::_getCostCenter($tmp_vendor->getId()));
00307 $worksheet->writeString($counter,4,$tmp_purchaser->getLogin());
00308 $worksheet->writeString($counter,5,strftime('%Y-%m-%d %R',$booking['order_date']));
00309
00310
00311
00312
00313
00314
00315
00316
00317 $worksheet->writeString($counter,6,$booking['duration']);
00318 $worksheet->writeString($counter,7,$booking['price']);
00319
00320 $payed_access = $booking['payed'] ?
00321 $this->lng->txt('yes') :
00322 $this->lng->txt('no');
00323
00324 $payed_access .= '/';
00325 $payed_access .= $booking['access'] ?
00326 $this->lng->txt('yes') :
00327 $this->lng->txt('no');
00328
00329 $worksheet->writeString($counter,8,$payed_access);
00330
00331 unset($tmp_obj);
00332 unset($tmp_vendor);
00333 unset($tmp_purchaser);
00334
00335 ++$counter;
00336 }
00337 }
00338
00339 function editStatistic($a_show_confirm_delete = false)
00340 {
00341 if(!isset($_GET['booking_id']))
00342 {
00343 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00344 $this->showStatistics();
00345
00346 return true;
00347 }
00348
00349 $this->showButton('showStatistics',$this->lng->txt('back'));
00350
00351 $this->tpl->addBlockfile('ADM_CONTENT','adm_content','tpl.paya_edit_statistic.html',true);
00352 $this->ctrl->setParameter($this,'booking_id',(int) $_GET['booking_id']);
00353
00354
00355 if($a_show_confirm_delete)
00356 {
00357 $this->tpl->setCurrentBlock("confirm_delete");
00358 $this->tpl->setVariable("CONFIRM_FORMACTION",$this->ctrl->getFormAction($this));
00359 $this->tpl->setVariable("TXT_CANCEL",$this->lng->txt('cancel'));
00360 $this->tpl->setVariable("CONFIRM_CMD",'performDelete');
00361 $this->tpl->setVariable("TXT_CONFIRM",$this->lng->txt('confirm'));
00362 $this->tpl->parseCurrentBlock();
00363 }
00364
00365
00366 $this->__initBookingObject();
00367 $bookings = $this->booking_obj->getBookings();
00368 $booking = $bookings[(int) $_GET['booking_id']];
00369
00370
00371 $tmp_user =& ilObjectFactory::getInstanceByObjId($booking['customer_id']);
00372
00373
00374
00375 $this->tpl->setVariable("STAT_FORMACTION",$this->ctrl->getFormAction($this));
00376 $this->tpl->setVariable("TYPE_IMG",ilUtil::getImagePath('icon_usr_b.gif'));
00377 $this->tpl->setVariable("ALT_IMG",$this->lng->txt('obj_usr'));
00378 $this->tpl->setVariable("TITLE",$tmp_user->getFullname().' ['.$tmp_user->getLogin().']');
00379
00380
00381 $this->tpl->setVariable("TXT_TRANSACTION",$this->lng->txt('paya_transaction'));
00382 $this->tpl->setVariable("TXT_VENDOR",$this->lng->txt('paya_vendor'));
00383 $this->tpl->setVariable("TXT_PAY_METHOD",$this->lng->txt('paya_pay_method'));
00384 $this->tpl->setVariable("TXT_ORDER_DATE",$this->lng->txt('paya_order_date'));
00385 $this->tpl->setVariable("TXT_DURATION",$this->lng->txt('duration'));
00386 $this->tpl->setVariable("TXT_PRICE",$this->lng->txt('price_a'));
00387 $this->tpl->setVariable("TXT_PAYED",$this->lng->txt('paya_payed'));
00388 $this->tpl->setVariable("TXT_ACCESS",$this->lng->txt('paya_access'));
00389
00390 $this->tpl->setVariable("TRANSACTION",$booking['transaction']);
00391
00392 $tmp_vendor =& ilObjectFactory::getInstanceByObjId($booking['b_vendor_id']);
00393
00394 $this->tpl->setVariable("VENDOR",$tmp_vendor->getFullname().' ['.$tmp_vendor->getLogin().']');
00395
00396 switch($booking['b_pay_method'])
00397 {
00398 case $this->pobject->PAY_METHOD_BILL:
00399 $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('pays_bill'));
00400 break;
00401
00402 case $this->pobject->PAY_METHOD_BMF:
00403 $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('pays_bmf'));
00404 break;
00405
00406 default:
00407 $this->tpl->setVariable("PAY_METHOD",$this->lng->txt('paya_pay_method_not_specified'));
00408 break;
00409 }
00410 $this->tpl->setVariable("ORDER_DATE",date('Y m d H:i:s',$booking['order_date']));
00411 $this->tpl->setVariable("DURATION",$booking['duration'].' '.$this->lng->txt('paya_months'));
00412 $this->tpl->setVariable("PRICE",$booking['price']);
00413
00414 $yes_no = array(0 => $this->lng->txt('no'),1 => $this->lng->txt('yes'));
00415
00416 $this->tpl->setVariable("PAYED",ilUtil::formSelect((int) $booking['payed'],'payed',$yes_no,false,true));
00417 $this->tpl->setVariable("ACCESS",ilUtil::formSelect((int) $booking['access'],'access',$yes_no,false,true));
00418
00419
00420 $this->tpl->setVariable("INPUT_CMD",'updateStatistic');
00421 $this->tpl->setVariable("INPUT_VALUE",$this->lng->txt('save'));
00422
00423 $this->tpl->setVariable("DELETE_CMD",'deleteStatistic');
00424 $this->tpl->setVariable("DELETE_VALUE",$this->lng->txt('delete'));
00425 }
00426
00427 function updateStatistic()
00428 {
00429 if(!isset($_GET['booking_id']))
00430 {
00431 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00432 $this->showStatistics();
00433
00434 return true;
00435 }
00436 $this->__initBookingObject();
00437
00438 $this->booking_obj->setBookingId((int) $_GET['booking_id']);
00439 $this->booking_obj->setAccess((int) $_POST['access']);
00440 $this->booking_obj->setPayed((int) $_POST['payed']);
00441
00442 if($this->booking_obj->update())
00443 {
00444 sendInfo($this->lng->txt('paya_updated_booking'));
00445
00446 $this->showStatistics();
00447 return true;
00448 }
00449 else
00450 {
00451 sendInfo($this->lng->txt('paya_error_update_booking'));
00452 $this->showStatistics();
00453
00454 return true;
00455 }
00456 }
00457
00458 function deleteStatistic()
00459 {
00460 if(!isset($_GET['booking_id']))
00461 {
00462 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00463 $this->showStatistics();
00464
00465 return true;
00466 }
00467 sendInfo($this->lng->txt('paya_sure_delete_stat'));
00468
00469 $this->editStatistic(true);
00470
00471 return true;
00472 }
00473
00474 function performDelete()
00475 {
00476 if(!isset($_GET['booking_id']))
00477 {
00478 sendInfo($this->lng->txt('paya_no_booking_id_given'));
00479 $this->showStatistics();
00480
00481 return true;
00482 }
00483
00484 $this->__initBookingObject();
00485 $this->booking_obj->setBookingId((int) $_GET['booking_id']);
00486 if(!$this->booking_obj->delete())
00487 {
00488 die('Error deleting booking');
00489 }
00490 sendInfo($this->lng->txt('pay_deleted_booking'));
00491
00492 $this->showStatistics();
00493
00494 return true;
00495 }
00496
00497
00498 function __showStatisticTable($a_result_set)
00499 {
00500 $tbl =& $this->initTableGUI();
00501 $tpl =& $tbl->getTemplateObject();
00502
00503
00504 $tpl->setCurrentBlock("tbl_form_header");
00505
00506 $tpl->setVariable("FORMACTION",$this->ctrl->getFormAction($this));
00507 $tpl->parseCurrentBlock();
00508
00509
00510
00511
00512
00513
00514
00515
00516
00517
00518
00519
00520
00521
00522
00523
00524
00525
00526 $tbl->setTitle($this->lng->txt("paya_statistic"),"icon_pays_b.gif",$this->lng->txt("paya_statistic"));
00527 $tbl->setHeaderNames(array($this->lng->txt("paya_transaction"),
00528 $this->lng->txt("title"),
00529 $this->lng->txt("paya_vendor"),
00530 $this->lng->txt("paya_customer"),
00531 $this->lng->txt("paya_order_date"),
00532 $this->lng->txt("duration"),
00533 $this->lng->txt("price_a"),
00534 $this->lng->txt("paya_payed_access"),
00535 $this->lng->txt("edit")));
00536
00537 $tbl->setHeaderVars(array("transaction",
00538 "title",
00539 "vendor",
00540 "customer",
00541 "order_date",
00542 "duration",
00543 "price",
00544 "payed_access",
00545 "options"),
00546 array("cmd" => "",
00547 "cmdClass" => "ilpaymentstatisticgui",
00548 "cmdNode" => $_GET["cmdNode"]));
00549
00550 $offset = $_GET["offset"];
00551 $order = $_GET["sort_by"];
00552 $direction = $_GET["sort_order"] ? $_GET['sort_order'] : 'desc';
00553
00554 $tbl->setOrderColumn($order,'order_date');
00555 $tbl->setOrderDirection($direction);
00556 $tbl->setOffset($offset);
00557 $tbl->setLimit($_GET["limit"]);
00558 $tbl->setMaxCount(count($a_result_set));
00559 $tbl->setFooter("tblfooter",$this->lng->txt("previous"),$this->lng->txt("next"));
00560 $tbl->setData($a_result_set);
00561
00562
00563 $tbl->render();
00564
00565 $this->tpl->setVariable("STATISTIC_TABLE",$tbl->tpl->get());
00566
00567 return true;
00568 }
00569
00570 function __initBookingObject()
00571 {
00572 include_once './payment/classes/class.ilPaymentBookings.php';
00573
00574 $this->booking_obj =& new ilPaymentBookings($this->user_obj->getId());
00575 }
00576
00577 function __showButton($a_cmd,$a_text,$a_target = '')
00578 {
00579 $this->tpl->addBlockfile("BUTTONS", "buttons", "tpl.buttons.html");
00580
00581
00582 $this->tpl->setCurrentBlock("btn_cell");
00583 $this->tpl->setVariable("BTN_LINK",$this->ctrl->getLinkTarget($this,$a_cmd));
00584 $this->tpl->setVariable("BTN_TXT",$a_text);
00585 if($a_target)
00586 {
00587 $this->tpl->setVariable("BTN_TARGET",$a_target);
00588 }
00589
00590 $this->tpl->parseCurrentBlock();
00591 }
00592
00593 }
00594 ?>