Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- if($action == "masspay"){
- checkContactPermission("invoices");
- $ca->setTemplate("masspay");
- if(!$CONFIG['EnableMassPay']) {
- header("Location: clientarea.php");
- exit();
- }
- if($all) {
- $invoiceids = array();
- $result = select_query("tblinvoices", "id",array("userid" => $client->getID(), "status" => "Unpaid", "(select count(id) from tblinvoiceitems where invoiceid=tblinvoices.id and type='Invoice')" => array("sqltype" => "<=","value" => 0)), "id","DESC");
- while ($data = mysql_fetch_array($result)) {
- $invoiceids[] = $data['id'];
- }
- } else {
- if (count($invoiceids) == 0) {
- header("Location: clientarea.php");
- exit();
- }
- if(count($invoiceids) == 1) {
- header("Location: viewinvoice.php?id=".$invoiceids[0]);
- exit();
- }
- foreach($invoiceids as $k=> $v) {
- $invoiceids[$k] = (int) $v;
- }
- }
- $xmasspays = array();
- $result = select_query("tblinvoiceitems","invoiceid,relid", array("tblinvoiceitems.userid"=> $client->getID(),"tblinvoiceitems.type"=> "Invoice","tblinvoices.status" =>"Unpaid"), "", "", "","tblinvoices ON tblinvoices.id=tblinvoiceitems.invoiceid");
- while ($data = mysql_fetch_array($result)) {
- $xmasspays[$data[0]][$data[1]] = 1;
- }
- if(count($xmasspays)) {
- $numsel = count($invoiceids);
- foreach($xmasspays as $iid => $vals) {
- if(count($vals) == $numsel) {
- foreach($invoiceids as $z) {
- unset($vals[$z]);
- }
- if (!count($vals)) {
- redir("id=".$iid,"viewinvoice.php");
- }
- }
- }
- }
- if($geninvoice) {
- check_token();
- }
- $paymentmethods = getGatewaysArray();
- if(!array_key_exists($paymentmethod, $paymentmethods)) {
- $paymentmethod = getClientsPaymentMethod($client->getID());
- }
- $paymentmethod = WHMCS_Gateways::makesafename($paymentmethod);
- /*
- if(!$paymentmethod) {
- exit("Unexpected payment method value. Exiting.");
- }
- */
- $subtotal = $credit = $tax = $tax2 = $total = $partialpayments = 0;
- $invoiceitems = array();
- foreach($invoiceids as $invoiceid) {
- $result = select_query("tblinvoices", "", array("id" => $invoiceid,"userid" => $client->getID()));
- $data = mysql_fetch_array($result);
- $subtotal += $data['subtotal'];
- $credit += $data['credit'];
- $tax += $data['tax'];
- $tax2 += $data['tax2'];
- $thistotal = $data['total'];
- $total += $thistotal;
- $result = select_query("tblaccounts", "SUM(amountin)", array("invoiceid" => $invoiceid));
- $data = mysql_fetch_array($result);
- $thispayments = $data[0];
- $partialpayments += $thispayments;
- $thistotal = $thistotal - $thispayments;
- if($geninvoice) {
- insert_query("tblinvoiceitems", array("userid" => $client->getID(), "type" =>"Invoice", "relid" => $invoiceid, "description"=> $_LANG['invoicenumber'].$invoiceid, "amount" => $thistotal, "duedate" =>"now()","paymentmethod" => $paymentmethod));
- }
- $result = select_query("tblinvoiceitems", "",array("invoiceid" => $invoiceid));
- while ($data = mysql_fetch_array($result)) {
- $invoiceitems[$invoiceid][] = array("id"=> $data['id'],"description" => nl2br($data['description']),"amount" => formatCurrency($data['amount']), "tax" => $data['tax']);
- }
- }
- if($geninvoice) {
- foreach($xmasspays as $iid => $vals) {
- update_query("tblinvoices", array("status" => "Cancelled"), array("id" => $iid,"userid" => $client->getID()));
- }
- require("includes/processinvoices.php");
- $invoiceid =createInvoices($client->getID(), true, true);
- $result = select_query("tblpaymentgateways","value", array("gateway"=> $paymentmethod,"setting" => "type"));
- $data = mysql_fetch_array($result);
- $gatewaytype = $data['value'];
- if($gatewaytype == "CC" || $gatewaytype == "OfflineCC") {
- if(!isValidforPath($paymentmethod)) {
- exit("Invalid Payment Gateway Name");
- }
- $gatewaypath = ROOTDIR."/modules/gateways/".$paymentmethod.".php";
- if (file_exists($gatewaypath)) {
- require_once($gatewaypath);
- }
- if (!function_exists($paymentmethod."_link")) {
- header("Location: creditcard.php?invoiceid=".$invoiceid);
- exit();
- }
- }
- $result = select_query("tblinvoices", "", array("userid" => $client->getID(), "id" => $invoiceid));
- $data = mysql_fetch_array($result);
- $id = $data['id'];
- $total = $data['total'];
- $paymentmethod = $data['paymentmethod'];
- $clientsdetails = getClientsDetails($client->getID());
- $params = getGatewayVariables($paymentmethod, $id, $total);
- $paymentbutton = call_user_func($paymentmethod."_link",$params);
- $ca->setTemplate("forwardpage");
- $ca->assign("message", $_LANG['forwardingtogateway']);
- $ca->assign("code", $paymentbutton);
- $ca->assign("invoiceid",$id);
- $ca->output();
- exit();
- }
- $smartyvalues['subtotal'] = formatCurrency($subtotal);
- if($credit) {
- $smartyvalues['credit'] = formatCurrency($credit);
- }
- if($tax) {
- $smartyvalues['tax'] = formatCurrency($tax);
- }
- if ($tax2) {
- $smartyvalues['tax2'] = formatCurrency($tax2);
- }
- if ($partialpayments) {
- $smartyvalues['partialpayments'] = formatCurrency($partialpayments);
- }
- $smartyvalues['total'] = formatCurrency($total - $partialpayments);
- $smartyvalues['invoiceitems'] = $invoiceitems;
- $gatewayslist = showPaymentGatewaysList();
- $smartyvalues['gateways'] = $gatewayslist;
- $smartyvalues['defaultgateway'] = key($gatewayslist);
- }
Advertisement
Add Comment
Please, Sign In to add comment