forked from puarudz/WHMCS-7.8.0-decoded
-
Notifications
You must be signed in to change notification settings - Fork 0
/
viewinvoice.php
executable file
·116 lines (114 loc) · 5.21 KB
/
viewinvoice.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
<?php
/*
* @ PHP 5.6
* @ Decoder version : 1.0.0.1
* @ Release on : 24.03.2018
* @ Website : http://EasyToYou.eu
*/
define("CLIENTAREA", true);
require "init.php";
require "includes/gatewayfunctions.php";
require "includes/invoicefunctions.php";
require "includes/clientfunctions.php";
require "includes/adminfunctions.php";
$id = $invoiceid = (int) $whmcs->get_req_var("id");
$breadcrumbnav = "<a href=\"index.php\">" . $whmcs->get_lang("globalsystemname") . "</a> > <a href=\"clientarea.php\">" . $whmcs->get_lang("clientareatitle") . "</a> > <a href=\"clientarea.php?action=invoices\">" . $_LANG["invoices"] . "</a> > <a href=\"viewinvoice.php?id=" . $invoiceid . "\">" . $_LANG["invoicenumber"] . $invoiceid . "</a>";
$existingLanguage = NULL;
if (isset($_SESSION["adminid"]) && $whmcs->get_req_var("view_as_client")) {
$userId = WHMCS\Invoice::getUserIdByInvoiceId($invoiceid);
if ($userId) {
$existingLanguage = getUsersLang($userId);
}
}
initialiseClientArea($whmcs->get_lang("invoicestitle") . $invoiceid, "", "", "", $breadcrumbnav);
if (!isset($_SESSION["uid"]) && !isset($_SESSION["adminid"])) {
$goto = "viewinvoice";
require "login.php";
exit;
}
$invoice = new WHMCS\Invoice();
$invoiceexists = true;
try {
$invoice->setID($invoiceid);
} catch (Exception $e) {
$invoiceexists = false;
}
$allowedaccess = isset($_SESSION["adminid"]) ? checkPermission("Manage Invoice", true) : $invoice->isAllowed();
if (!$invoiceexists || !$allowedaccess) {
$smarty->assign("error", "on");
$smarty->assign("invalidInvoiceIdRequested", true);
outputClientArea("viewinvoice", true);
exit;
}
$smarty->assign("invalidInvoiceIdRequested", false);
checkContactPermission("invoices");
if ($invoice->getData("status") == "Paid" && isset($_SESSION["orderdetails"]) && $_SESSION["orderdetails"]["InvoiceID"] == $invoiceid && !$_SESSION["orderdetails"]["paymentcomplete"]) {
$_SESSION["orderdetails"]["paymentcomplete"] = true;
redir("a=complete", "cart.php");
}
$gateway = $whmcs->get_req_var("gateway");
if ($gateway) {
check_token();
$gateways = new WHMCS\Gateways();
$validgateways = $gateways->getAvailableGateways($invoiceid);
if (array_key_exists($gateway, $validgateways)) {
update_query("tblinvoices", array("paymentmethod" => $gateway), array("id" => $invoiceid));
run_hook("InvoiceChangeGateway", array("invoiceid" => $invoiceid, "paymentmethod" => $gateway));
}
redir("id=" . $invoiceid);
}
$creditbal = get_query_val("tblclients", "credit", array("id" => $invoice->getData("userid")));
if ($invoice->getData("status") == "Unpaid" && 0 < $creditbal && !$invoice->isAddFundsInvoice()) {
$balance = $invoice->getData("balance");
$creditamount = $whmcs->get_req_var("creditamount");
if ($whmcs->get_req_var("applycredit") && 0 < $creditamount) {
check_token();
if ($creditbal < $creditamount) {
echo $_LANG["invoiceaddcreditovercredit"];
exit;
}
if ($balance < $creditamount) {
echo $_LANG["invoiceaddcreditoverbalance"];
exit;
}
applyCredit($invoiceid, $invoice->getData("userid"), $creditamount);
redir("id=" . $invoiceid);
}
$smartyvalues["manualapplycredit"] = true;
$clientCurrency = getCurrency($invoice->getData("userid"));
$smartyvalues["totalcredit"] = formatCurrency($creditbal, $clientCurrency["id"]) . generate_token("form");
if (!$creditamount) {
$creditamount = $balance <= $creditbal ? $balance : $creditbal;
}
$smartyvalues["creditamount"] = $creditamount;
}
$outputvars = $invoice->getOutput();
$smartyvalues = array_merge($smartyvalues, $outputvars);
$invoiceitems = $invoice->getLineItems();
$smartyvalues["invoiceitems"] = $invoiceitems;
$transactions = $invoice->getTransactions();
$smartyvalues["transactions"] = $transactions;
$paymentbutton = $invoice->getData("status") == "Unpaid" && 0 < $invoice->getData("balance") ? $invoice->getPaymentLink() : "";
$smartyvalues["paymentbutton"] = $paymentbutton;
$smartyvalues["paymentSuccess"] = (bool) $whmcs->get_req_var("paymentsuccess");
$smartyvalues["paymentFailed"] = (bool) $whmcs->get_req_var("paymentfailed");
$smartyvalues["pendingReview"] = (bool) $whmcs->get_req_var("pendingreview");
$smartyvalues["offlineReview"] = (bool) $whmcs->get_req_var("offlinepaid");
$smartyvalues["offlinepaid"] = (bool) $whmcs->get_req_var("offlinepaid");
$smartyvalues["paymentSuccessAwaitingNotification"] = $invoice->showPaymentSuccessAwaitingNotificationMsg($smartyvalues["paymentSuccess"]);
if ($whmcs->get_config("AllowCustomerChangeInvoiceGateway")) {
$smartyvalues["allowchangegateway"] = true;
$gateways = new WHMCS\Gateways();
$availablegateways = $gateways->getAvailableGateways($invoiceid);
$frm = new WHMCS\Form();
$gatewaydropdown = generate_token("form") . $frm->dropdown("gateway", $availablegateways, $invoice->getData("paymentmodule"), "submit()");
$smartyvalues["gatewaydropdown"] = $gatewaydropdown;
} else {
$smartyvalues["allowchangegateway"] = false;
}
$smartyvalues["taxIdLabel"] = Lang::trans(WHMCS\Billing\Tax\Vat::getLabel());
outputClientArea("viewinvoice", true, array("ClientAreaPageViewInvoice"));
if ($existingLanguage) {
swapLang($existingLanguage);
}
?>