Development version, definitely unstable and insecure...

This commit is contained in:
Kumi 2021-08-25 19:27:25 +02:00
commit 7c71c6506d
4 changed files with 148 additions and 0 deletions

44
apply.php Normal file
View file

@ -0,0 +1,44 @@
<?php
require_once('../../../init.php');
require_once('functions.php');
$currentUser = localAPI("GetAdminDetails");
if ($currentUser["result"] == "success") {
$billables = array();
$prices = array();
$taxed = array();
foreach ($_POST["billable"] as $billableid) {
$billable = getBillable($billableid);
$billables[] = $billable->description;
$prices[] = $billable->amount;
$taxed[] = true;
}
print_r($billables);
print_r($prices);
print_r($taxed);
$result = localAPI("UpdateInvoice", array(
'invoiceid' => $_POST["invoiceid"],
'newitemdescription' => $billables,
'newitemamount' => $prices,
'newitemtaxed' => $taxed
));
if (!$result["result"] == "success") {
die("Could not apply billables to invoice.");
}
foreach ($_POST["billable"] as $billableid) {
incrementBillableInvoices($billableid);
}
header("Location: /admin/invoices.php?action=edit&id=" . $_POST["invoiceid"]);
} else {
die();
}

32
functions.php Normal file
View file

@ -0,0 +1,32 @@
<?php
use WHMCS\Database\Capsule;
function getBillables($userid, $invoiced=false) {
$billables = Capsule::table('tblbillableitems')
->where("userid", $userid);
if (!$invoiced) {
$billables = $billables->where("invoicecount", 0);
}
$billables = $billables->get();
return $billables;
}
function getBillable($billableid) {
$billables = Capsule::table('tblbillableitems')
->where("id", $billableid)
->get();
foreach ($billables as $billable) {
return $billable;
}
}
function incrementBillableInvoices($billableid) {
Capsule::table('tblbillableitems')
->where("id", $billableid)
->increment("invoicecount");
}

59
hooks.php Normal file
View file

@ -0,0 +1,59 @@
<?php
require_once("functions.php");
add_hook('AdminInvoicesControlsOutput', 99, function($vars) {
$billables = getBillables($vars["userid"]);
print('<br><input type="button" value="Apply Billable Items" onclick="jQuery(\'#applyBillables\').modal(\'show\');" class="button btn btn-default">');
print('<div class="modal fade" id="applyBillables" tabindex="-1" role="dialog" aria-labelledby="applyBillablesLabel" aria-hidden="true" style="display: none;">
<form method="post" action="../modules/addons/whmcs_apply_billables/apply.php">
<input type="hidden" name="invoiceid" value="' . $vars["invoiceid"] . '" class="id-target">
<div class="modal-dialog">
<div class="modal-content panel panel-primary">
<div class="modal-header panel-heading">
<button type="button" class="close" data-dismiss="modal">
<span aria-hidden="true">×</span>
<span class="sr-only">Close</span>
</button>
<h4 class="modal-title">Select Billable Items</h4>
</div>
<div class="modal-body panel-body">
<table>
<tr>
<th></th>
<th>ID</th>
<th>Description</th>
<th>Hours</th>
<th>Amount</th>
</tr>
');
foreach ($billables as $billable) {
print('
<tr>
<td><input type="checkbox" name="billable[]" value="' . $billable->id . '"></td>
<td>' . $billable->id . '</td>
<td>' . $billable->description . '</td>
<td>' . $billable->hours . '</td>
<td>' . $billable->amount . '</td>
</tr>
');
};
print('
</table>
</div>
<div class="modal-footer panel-footer">
<button type="button" id="doDeleteClient-cancel" class="btn btn-default" data-dismiss="modal">
Cancel
</button>
<button type="submit" id="doDeleteClient-ok" class="btn btn-primary">
OK
</button>
</div>
</div>
</div>
</form>
</div>');
});

13
whmcs_apply_billables.php Normal file
View file

@ -0,0 +1,13 @@
<?php
if (!defined("WHMCS")) {
die("This file cannot be accessed directly");
}
function whmcs_apply_billables_MetaData()
{
return array(
'DisplayName' => 'Apply Billables to Invoices',
'APIVersion' => '1.1'
);
}