Esempio n. 1
0
    if ($page) {
        $userid .= "&page=" . $page;
    }
    redir("userid=" . $userid . "&filter=1");
}
if ($masspay) {
    check_token("WHMCS.admin.default");
    if (count($selectedinvoices) < 2) {
        if ($page) {
            $userid .= "&page=" . $page;
        }
        redir("userid=" . $userid . "&masspayerr=1");
        exit;
    }
    $invoiceid = createInvoices($userid);
    $paymentmethod = getClientsPaymentMethod($userid);
    $invoiceitems = array();
    foreach ($selectedinvoices as $invoiceid) {
        $result = select_query("tblinvoices", "", array("id" => $invoiceid));
        $data = mysql_fetch_array($result);
        $subtotal += $data['subtotal'];
        $credit += $data['credit'];
        $tax += $data['tax'];
        $tax2 += $data['tax2'];
        $thistotal = $data['total'];
        $result = select_query("tblaccounts", "SUM(amountin)", array("invoiceid" => $invoiceid));
        $data = mysql_fetch_array($result);
        $thispayments = $data[0];
        $thistotal = $thistotal - $thispayments;
        insert_query("tblinvoiceitems", array("userid" => $userid, "type" => "Invoice", "relid" => $invoiceid, "description" => $_LANG['invoicenumber'] . $invoiceid, "amount" => $thistotal, "duedate" => "now()", "paymentmethod" => $paymentmethod));
    }
Esempio n. 2
0
        }
        if (0 < $data['tax2']) {
            echo "<tr bgcolor=\"#efefef\" style=\"text-align:right;font-weight:bold;\"><td>" . $data['taxrate2'] . "% " . $aInt->lang("fields", "tax") . "&nbsp;</td><td>" . formatCurrency($data['tax2']) . "</td></tr>";
        }
    }
    echo "<tr bgcolor=\"#efefef\" style=\"text-align:right;font-weight:bold;\"><td>" . $aInt->lang("fields", "credit") . "&nbsp;</td><td>" . formatCurrency($data['credit']) . "</td></tr>";
    echo "<tr bgcolor=\"#efefef\" style=\"text-align:right;font-weight:bold;\"><td>" . $aInt->lang("fields", "totaldue") . "&nbsp;</td><td>" . formatCurrency($data['total']) . "</td></tr>";
    echo "</table>";
    exit;
}
if ($action == "createinvoice") {
    check_token("WHMCS.admin.default");
    if (!checkActiveGateway()) {
        $aInt->gracefulExit($aInt->lang("gateways", "nonesetup"));
    }
    $gateway = getClientsPaymentMethod($userid);
    if ($CONFIG['TaxEnabled'] == "on") {
        $clientsdetails = getClientsDetails($userid);
        if (!$clientsdetails['taxexempt']) {
            $state = $clientsdetails['state'];
            $country = $clientsdetails['country'];
            $taxdata = getTaxRate(1, $state, $country);
            $taxdata2 = getTaxRate(2, $state, $country);
            $taxrate = $taxdata['rate'];
            $taxrate2 = $taxdata2['rate'];
        }
    }
    $duedate = date("Ymd", mktime(0, 0, 0, date("m"), date("d") + $CONFIG['CreateInvoiceDaysBefore'], date("Y")));
    $invoiceid = insert_query("tblinvoices", array("date" => "now()", "duedate" => $duedate, "userid" => $userid, "status" => "Unpaid", "paymentmethod" => $gateway, "taxrate" => $taxrate, "taxrate2" => $taxrate2));
    logActivity("Created Manual Invoice - Invoice ID: " . $invoiceid, $userid);
    if (1 < $CONFIG['InvoiceIncrement']) {
Esempio n. 3
0
                     }
                 }
             } else {
                 if ($id) {
                     redir("action=domaindetails&id=" . $id);
                 } else {
                     redir();
                 }
             }
         }
     }
 }
 if ($buy) {
     $smartyvalues['action'] = "buy";
     $smartyvalues['addon'] = $buy;
     $paymentmethod = getClientsPaymentMethod($client->getID());
     $domaintax = $whmcs->get_config("TaxDomains") ? 1 : 0;
     $invdesc = "";
     if ($buy == "dnsmanagement") {
         if ($confirm) {
             $invdesc = $_LANG['domainaddons'] . " (" . $_LANG['domainaddonsdnsmanagement'] . ") - " . $domain . " - 1 " . $_LANG['orderyears'];
             $invamt = $domaindnsmanagementprice;
             $addontype = "DNS";
         }
     } else {
         if ($buy == "emailfwd") {
             if ($confirm) {
                 $invdesc = $_LANG['domainaddons'] . " (" . $_LANG['domainemailforwarding'] . ") - " . $domain . " - 1 " . $_LANG['orderyears'];
                 $invamt = $domainemailforwardingprice;
                 $addontype = "EMF";
             }
Esempio n. 4
0
function createInvoicesProcess($data, $noemails = "", $nocredit = "")
{
    global $whmcs;
    global $cron;
    global $CONFIG;
    global $_LANG;
    global $invoicecount;
    global $invoiceid;
    $itemid = $data['id'];
    $userid = $data['userid'];
    $type = $data['type'];
    $relid = $data['relid'];
    $duedate = $data['duedate'];
    $paymentmethod = $invpaymentmethod = $data['paymentmethod'];
    if (!$invpaymentmethod) {
        if (!function_exists("getClientsPaymentMethod")) {
            require ROOTDIR . "/includes/clientfunctions.php";
        }
        $invpaymentmethod = getClientsPaymentMethod($userid);
        update_query("tblinvoiceitems", array("paymentmethod" => $invpaymentmethod), array("id" => $itemid));
    }
    if ($itemid) {
        if (get_query_val("tblinvoiceitems", "invoiceid", array("id" => $itemid))) {
            return false;
        }
    }
    $taxrate = $taxrate2 = 0;
    if ($CONFIG['TaxEnabled']) {
        $data = get_query_vals("tblclients", "taxexempt,state,country,separateinvoices", array("id" => $userid));
        $taxexempt = $data['taxexempt'];
        $taxstate = $data['state'];
        $taxcountry = $data['country'];
        if (!$taxexempt) {
            $taxrate = getTaxRate(1, $taxstate, $taxcountry);
            $taxrate2 = getTaxRate(2, $taxstate, $taxcountry);
            $taxrate = $taxrate['rate'];
            $taxrate2 = $taxrate2['rate'];
        }
    }
    $invoiceid = insert_query("tblinvoices", array("date" => "now()", "duedate" => $duedate, "userid" => $userid, "status" => "Unpaid", "taxrate" => $taxrate, "taxrate2" => $taxrate2, "paymentmethod" => $invpaymentmethod, "notes" => $invoicenotes));
    if ($itemid) {
        update_query("tblinvoiceitems", array("invoiceid" => $invoiceid), array("invoiceid" => "0", "userid" => $userid, "type" => "Promo" . $type, "relid" => $relid));
        $where = array("id" => $itemid);
    } else {
        $where = array("invoiceid" => "", "duedate" => $duedate, "userid" => $userid, "paymentmethod" => $paymentmethod);
    }
    update_query("tblinvoiceitems", array("invoiceid" => $invoiceid), $where);
    logActivity("Created Invoice - Invoice ID: " . $invoiceid, $userid);
    if (is_object($cron)) {
        $cron->logActivityDebug("Generated Invoice #" . $invoiceid);
    }
    $billableitemstax = $CONFIG['TaxEnabled'] && $CONFIG['TaxCustomInvoices'] ? "1" : "0";
    $result2 = select_query("tblbillableitems", "", array("userid" => $userid, "invoiceaction" => "2", "invoicecount" => "0"));
    while ($data = mysql_fetch_array($result2)) {
        insert_query("tblinvoiceitems", array("invoiceid" => $invoiceid, "userid" => $userid, "type" => "Item", "relid" => $data['id'], "description" => $data['description'], "amount" => $data['amount'], "taxed" => $billableitemstax));
        update_query("tblbillableitems", array("invoicecount" => "+1"), array("id" => $data['id']));
    }
    updateInvoiceTotal($invoiceid);
    $data2 = get_query_vals("tblclients", "credit,groupid", array("id" => $userid));
    $credit = $data2['credit'];
    $groupid = $data2['groupid'];
    $data2 = get_query_vals("tblinvoices", "subtotal,total", array("id" => $invoiceid));
    $subtotal = $data2['subtotal'];
    $total = $data2['total'];
    $isaddfundsinvoice = get_query_val("tblinvoiceitems", "COUNT(id)", "invoiceid='" . $invoiceid . "' AND (type='AddFunds' OR type='Invoice')");
    if ($groupid && !$isaddfundsinvoice) {
        $discountpercent = get_query_val("tblclientgroups", "discountpercent", array("id" => $groupid));
        if (0 < $discountpercent) {
            $discountamount = $subtotal * ($discountpercent / 100) * (0 - 1);
            insert_query("tblinvoiceitems", array("invoiceid" => $invoiceid, "userid" => $userid, "type" => "GroupDiscount", "description" => $_LANG['clientgroupdiscount'], "amount" => $discountamount, "taxed" => "1"));
            updateInvoiceTotal($invoiceid);
            $data2 = get_query_vals("tblclients", "credit,groupid", array("id" => $userid));
            $credit = $data2['credit'];
            $groupid = $data2['groupid'];
            $data2 = get_query_vals("tblinvoices", "subtotal,total", array("id" => $invoiceid));
            $subtotal = $data2['subtotal'];
            $total = $data2['total'];
        }
    }
    if ($whmcs->get_config("ContinuousInvoiceGeneration")) {
        $result2 = select_query("tblinvoiceitems", "", array("invoiceid" => $invoiceid));
        while ($data = mysql_fetch_array($result2)) {
            $type = $data['type'];
            $relid = $data['relid'];
            $nextinvoicedate = $data['duedate'];
            $year = substr($nextinvoicedate, 0, 4);
            $month = substr($nextinvoicedate, 5, 2);
            $day = substr($nextinvoicedate, 8, 2);
            $proratabilling = false;
            if ($type == "Hosting") {
                $data = get_query_vals("tblhosting", "billingcycle,packageid,regdate,nextduedate", array("id" => $relid));
                $billingcycle = $data['billingcycle'];
                $packageid = $data['packageid'];
                $regdate = $data['regdate'];
                $nextduedate = $data['nextduedate'];
                $data = get_query_vals("tblproducts", "proratabilling,proratadate,proratachargenextmonth", array("id" => $packageid));
                $proratabilling = $data['proratabilling'];
                $proratadate = $data['proratadate'];
                $proratachargenextmonth = $data['proratachargenextmonth'];
                $proratamonths = getBillingCycleMonths($billingcycle);
                $nextinvoicedate = date("Ymd", mktime(0, 0, 0, $month + $proratamonths, $day, $year));
            } else {
                if ($type == "Domain" || $type == "DomainRegister" || $type == "DomainTransfer") {
                    $data = get_query_vals("tbldomains", "registrationperiod,nextduedate", array("id" => $relid));
                    $registrationperiod = $data['registrationperiod'];
                    $nextduedate = explode("-", $data['nextduedate']);
                    $billingcycle = "";
                    $nextinvoicedate = date("Ymd", mktime(0, 0, 0, $nextduedate[1], $nextduedate[2], $nextduedate[0] + $registrationperiod));
                } else {
                    if ($type == "Addon") {
                        $billingcycle = get_query_val("tblhostingaddons", "billingcycle", array("id" => $relid));
                        $proratamonths = getBillingCycleMonths($billingcycle);
                        $nextinvoicedate = date("Ymd", mktime(0, 0, 0, $month + $proratamonths, $day, $year));
                    }
                }
            }
            if ($billingcycle == "One Time") {
                $nextinvoicedate = "00000000";
            }
            if ($regdate == $nextduedate && $proratabilling) {
                if ($billingcycle != "Monthly") {
                    $proratachargenextmonth = 0;
                }
                $orderyear = substr($regdate, 0, 4);
                $ordermonth = substr($regdate, 5, 2);
                $orderday = substr($regdate, 8, 2);
                if ($orderday < $proratadate) {
                    $proratamonth = $ordermonth;
                } else {
                    $proratamonth = $ordermonth + 1;
                }
                $days = (strtotime(date("Y-m-d", mktime(0, 0, 0, $proratamonth, $proratadate, $orderyear))) - strtotime(date("Y-m-d"))) / (60 * 60 * 24);
                $totaldays = 30;
                $nextinvoicedate = date("Y-m-d", mktime(0, 0, 0, $proratamonth, $proratadate, $orderyear));
                if ($proratachargenextmonth <= $orderday && $days < 31) {
                    $nextinvoicedate = date("Y-m-d", mktime(0, 0, 0, $proratamonth + $proratamonths, $proratadate, $orderyear));
                }
            }
            if ($type == "Hosting") {
                update_query("tblhosting", array("nextinvoicedate" => $nextinvoicedate), array("id" => $relid));
            }
            if ($type == "Domain" || $type == "DomainRegister" || $type == "DomainTransfer") {
                update_query("tbldomains", array("nextinvoicedate" => $nextinvoicedate), array("id" => $relid));
            }
            if ($type == "Addon") {
                update_query("tblhostingaddons", array("nextinvoicedate" => $nextinvoicedate), array("id" => $relid));
            }
        }
    }
    $doprocesspaid = false;
    if (!$nocredit && $credit != "0.00" && !$CONFIG['NoAutoApplyCredit']) {
        if ($total <= $credit) {
            $creditleft = $credit - $total;
            $credit = $total;
            $doprocesspaid = true;
        } else {
            $creditleft = 0;
        }
        logActivity("Credit Automatically Applied at Invoice Creation - Invoice ID: " . $invoiceid . " - Amount: " . $credit, $userid);
        insert_query("tblcredit", array("clientid" => $userid, "date" => "now()", "description" => "Credit Applied to Invoice #" . $invoiceid, "amount" => $credit * (0 - 1)));
        update_query("tblclients", array("credit" => $creditleft), array("id" => $userid));
        update_query("tblinvoices", array("credit" => $credit), array("id" => $invoiceid));
        updateInvoiceTotal($invoiceid);
    }
    run_hook("InvoiceCreationPreEmail", array("invoiceid" => $invoiceid));
    if ($doprocesspaid) {
        processPaidInvoice($invoiceid);
    }
    $result2 = select_query("tblpaymentgateways", "value", array("gateway" => $invpaymentmethod, "setting" => "type"));
    $data2 = mysql_fetch_array($result2);
    $paymenttype = $data2['value'];
    if ($noemails != "true") {
        sendMessage(($paymenttype == "CC" || $paymenttype == "OfflineCC" ? "Credit Card " : "") . "Invoice Created", $invoiceid);
    }
    $result2 = select_query("tblinvoices", "total", array("id" => $invoiceid, "status" => "Unpaid"));
    $data2 = mysql_fetch_array($result2);
    $total = $data2['total'];
    if ($total == "0.00") {
        processPaidInvoice($invoiceid);
    }
    run_hook("InvoiceCreated", array("invoiceid" => $invoiceid));
    $invoicetotal = 0;
    ++$invoicecount;
    if (1 < $CONFIG['InvoiceIncrement']) {
        $invoiceincrement = $CONFIG['InvoiceIncrement'] - 1;
        $counter = 1;
        while ($counter <= $invoiceincrement) {
            $tempinvoiceid = insert_query("tblinvoices", array("date" => "now()"));
            delete_query("tblinvoices", array("id" => $tempinvoiceid));
            $counter += 1;
        }
    }
}
Esempio n. 5
0
             $dynamictimes[$dti]['amount'] = $dynamictimes[$dti]['rate'] * ($dynamictimes[$dti]['seconds'] / 3600);
             if (0 < $dynamictimes[$dti]['seconds']) {
                 echo "<tr id=\"dynamictaskinvoiceitemholder" . $dti . "\">\n\t\t\t<td><input type=\"hidden\" name=\"taskid[" . $dti . "]\" value=\"" . $tasksdata['id'] . "\" /><input style=\"width:99%\" type=\"text\" name=\"description[" . $dti . "]\" value=\"" . $dynamictimes[$dti]['description'] . "\" /></td>\n\t\t\t<td><input type=\"hidden\" id=\"dynamicbillhours" . $dti . "\" name=\"hours[" . $dti . "]\" value=\"" . round($dynamictimes[$dti]['seconds'] / 3600, 2) . "\" /><input type=\"text\" name=\"displayhours[" . $dti . "]\" class=\"dynamicbilldisplayhours\" id=\"dynamicbilldisplayhours" . $dti . "\" name=\"hours[" . $dti . "]\" value=\"" . project_management_sec2hms($dynamictimes[$dti]['seconds']) . "\" /></td>\n\t\t\t<td><input type=\"text\" class=\"dynamicbillrate\" id=\"dynamicbillrate" . $dti . "\" name=\"rate[" . $dti . "]\" value=\"" . format_as_currency($dynamictimes[$dti]['rate']) . "\" /></td>\n\t\t\t<td><input type=\"text\" id=\"dynamicbillamount" . $dti . "\" name=\"amount[" . $dti . "]\" value=\"" . format_as_currency($dynamictimes[$dti]['amount'], 2) . "\" /></td>\n\t\t\t<td><a class=\"deldynamictaskinvoice\" id=\"deldynamictaskinvoice" . $dti . "\"><img src=\"images/delete.gif\"></a></td></tr>";
             }
             ++$dti;
         }
         echo "</table></div><p align=\"center\"><input type=\"submit\" value=\"" . $vars['_lang']['generatenow'] . "\" />&nbsp;<input type=\"submit\" onClick=\"form.action='" . $modulelink . "&a=dynamicinvoicegenerate&sendinvoicegenemail=true'\" value=\"" . $vars['_lang']['generatenowandemail'] . "\" />&nbsp;<input type=\"button\" id=\"dynamictasksinvoicecancel\" value=\"" . $vars['_lang']['cancel'] . "\" /></p>\n\t\t</form>";
     }
     exit;
 } else {
     if ($a == "dynamicinvoicegenerate") {
         if (!project_management_checkperm("Bill Tasks")) {
             redir("module=project_management");
         }
         $userid = get_query_val("mod_project", "userid", array("id" => $projectid));
         $gateway = function_exists("getClientsPaymentMethod") ? getClientsPaymentMethod($userid) : "paypal";
         if ($CONFIG['TaxEnabled'] == "on") {
             $clientsdetails = getClientsDetails($userid);
             if (!$clientsdetails['taxexempt']) {
                 $state = $clientsdetails['state'];
                 $country = $clientsdetails['country'];
                 $taxdata = getTaxRate(1, $state, $country);
                 $taxdata2 = getTaxRate(2, $state, $country);
                 $taxrate = $taxdata['rate'];
                 $taxrate2 = $taxdata2['rate'];
             }
         }
         $invoiceid = insert_query("tblinvoices", array("date" => "now()", "duedate" => "now()", "userid" => $userid, "status" => "Unpaid", "paymentmethod" => $gateway, "taxrate" => $taxrate, "taxrate2" => $taxrate2));
         foreach ($_REQUEST['taskid'] as $taski => $taskid) {
             update_query("mod_projecttasks", array("billed" => 1), array("id" => $taskid));
         }