-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathviewinvoice.php
145 lines (143 loc) · 6.88 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
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
<?php
/*
* @ PHP 7.2
* @ Decoder version : 1.0.0.4
* @ Release on : 09/06/2021
* @ 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 = $invoiceIdTitle = (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>";
$invoice = new WHMCS\Invoice();
$invoiceExists = true;
try {
$invoice->setID($invoiceid);
} catch (Exception $e) {
$invoiceExists = false;
$invoiceModel = $invoice->getModel();
$invoiceOwnerId = $invoiceModel->userid;
$adminUser = WHMCS\User\Admin::getAuthenticatedUser();
if ($adminUser && !checkPermission("Manage Invoice", true)) {
$adminUser = NULL;
}
$existingLanguage = NULL;
if ($adminUser && App::getFromRequest("view_as_client")) {
$existingLanguage = getUsersLang($invoiceOwnerId);
}
if ($invoiceExists && $invoice->getData("invoicenum")) {
$invoiceIdTitle = $invoice->getData("invoicenum");
}
initialiseClientArea($whmcs->get_lang("invoicestitle") . $invoiceIdTitle, "", "", "", $breadcrumbnav);
if (!$adminUser) {
Auth::requireLoginAndClient(true);
try {
if (!$invoiceExists) {
throw new Exception();
}
Auth::forceSwitchClientIdOrFail($invoiceOwnerId);
if ($invoiceModel->status == WHMCS\Billing\Invoice::STATUS_DRAFT) {
throw new Exception();
}
checkContactPermission("invoices");
} catch (Exception $e) {
$smarty->assign("error", "on");
$smarty->assign("invalidInvoiceIdRequested", true);
outputClientArea("viewinvoice", true);
exit;
}
}
$smarty->assign("invalidInvoiceIdRequested", false);
if (($invoice->getData("status") === "Paid" || $invoice->getData("status") === "Payment Pending") && 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)) {
$invoiceToUpdate = WHMCS\Billing\Invoice::find($invoiceid);
if ($invoiceToUpdate && $invoiceToUpdate->paymentmethod !== $gateway) {
$invoiceToUpdate->setPaymentMethod($gateway)->save();
}
run_hook("InvoiceChangeGateway", ["invoiceid" => $invoiceid, "paymentmethod" => $gateway]);
}
redir("id=" . $invoiceid);
}
$creditbal = get_query_val("tblclients", "credit", ["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"] = (int) $whmcs->get_req_var("paymentsuccess");
$smartyvalues["paymentInititated"] = (int) $whmcs->get_req_var("paymentinititated");
$smartyvalues["paymentFailed"] = (int) $whmcs->get_req_var("paymentfailed");
$smartyvalues["pendingReview"] = (int) $whmcs->get_req_var("pendingreview");
$smartyvalues["offlineReview"] = (int) $whmcs->get_req_var("offlinepaid");
$smartyvalues["offlinepaid"] = (int) $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);
$currency = Currency::factoryForClientArea();
foreach ($availablegateways as $module => $value) {
try {
$gatewayInterface = WHMCS\Module\Gateway::factory($module);
if (!$gatewayInterface->isSupportedCurrency($currency["code"])) {
unset($availablegateways[$module]);
}
} catch (Exception $e) {
unset($availablegateways[$module]);
}
}
$frm = new WHMCS\Form();
$gatewaydropdown = generate_token("form") . $frm->dropdown("gateway", $availablegateways, $invoice->getData("paymentmodule"), "submit()");
$smartyvalues["gatewaydropdown"] = $gatewaydropdown;
$smartyvalues["tokenInput"] = generate_token("form");
$smartyvalues["selectedGateway"] = $invoice->getData("paymentmodule");
$smartyvalues["availableGateways"] = $availablegateways;
} else {
$smartyvalues["allowchangegateway"] = false;
}
$smartyvalues["taxIdLabel"] = Lang::trans(WHMCS\Billing\Tax\Vat::getLabel());
outputClientArea("viewinvoice", true, ["ClientAreaPageViewInvoice"]);
if ($existingLanguage) {
swapLang($existingLanguage);
}
}
?>