andripzf

Client Area 5.2.10

May 15th, 2014
594
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 4.96 KB | None | 0 0
  1. if($action == "masspay"){
  2. checkContactPermission("invoices");
  3. $ca->setTemplate("masspay");
  4. if(!$CONFIG['EnableMassPay']) {
  5. header("Location: clientarea.php");
  6. exit();
  7. }
  8.  
  9. if($all) {
  10. $invoiceids = array();
  11. $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");
  12. while ($data = mysql_fetch_array($result)) {
  13. $invoiceids[] = $data['id'];
  14. }
  15. } else {
  16. if (count($invoiceids) == 0) {
  17. header("Location: clientarea.php");
  18. exit();
  19. }
  20.  
  21. if(count($invoiceids) == 1) {
  22. header("Location: viewinvoice.php?id=".$invoiceids[0]);
  23. exit();
  24. }
  25. foreach($invoiceids as $k=> $v) {
  26. $invoiceids[$k] = (int) $v;
  27. }
  28. }
  29. $xmasspays = array();
  30. $result = select_query("tblinvoiceitems","invoiceid,relid", array("tblinvoiceitems.userid"=> $client->getID(),"tblinvoiceitems.type"=> "Invoice","tblinvoices.status" =>"Unpaid"), "", "", "","tblinvoices ON tblinvoices.id=tblinvoiceitems.invoiceid");
  31. while ($data = mysql_fetch_array($result)) {
  32. $xmasspays[$data[0]][$data[1]] = 1;
  33. }
  34. if(count($xmasspays)) {
  35. $numsel = count($invoiceids);
  36. foreach($xmasspays as $iid => $vals) {
  37. if(count($vals) == $numsel) {
  38. foreach($invoiceids as $z) {
  39. unset($vals[$z]);
  40. }
  41. if (!count($vals)) {
  42. redir("id=".$iid,"viewinvoice.php");
  43. }
  44. }
  45. }
  46. }
  47. if($geninvoice) {
  48. check_token();
  49. }
  50. $paymentmethods = getGatewaysArray();
  51. if(!array_key_exists($paymentmethod, $paymentmethods)) {
  52. $paymentmethod = getClientsPaymentMethod($client->getID());
  53. }
  54. $paymentmethod = WHMCS_Gateways::makesafename($paymentmethod);
  55.  
  56. /*
  57. if(!$paymentmethod) {
  58. exit("Unexpected payment method value. Exiting.");
  59. }
  60. */
  61.  
  62. $subtotal = $credit = $tax = $tax2 = $total = $partialpayments = 0;
  63. $invoiceitems = array();
  64. foreach($invoiceids as $invoiceid) {
  65. $result = select_query("tblinvoices", "", array("id" => $invoiceid,"userid" => $client->getID()));
  66. $data = mysql_fetch_array($result);
  67. $subtotal += $data['subtotal'];
  68. $credit += $data['credit'];
  69. $tax += $data['tax'];
  70. $tax2 += $data['tax2'];
  71. $thistotal = $data['total'];
  72. $total += $thistotal;
  73. $result = select_query("tblaccounts", "SUM(amountin)", array("invoiceid" => $invoiceid));
  74. $data = mysql_fetch_array($result);
  75. $thispayments = $data[0];
  76. $partialpayments += $thispayments;
  77. $thistotal = $thistotal - $thispayments;
  78.  
  79. if($geninvoice) {
  80. insert_query("tblinvoiceitems", array("userid" => $client->getID(), "type" =>"Invoice", "relid" => $invoiceid, "description"=> $_LANG['invoicenumber'].$invoiceid, "amount" => $thistotal, "duedate" =>"now()","paymentmethod" => $paymentmethod));
  81. }
  82.  
  83. $result = select_query("tblinvoiceitems", "",array("invoiceid" => $invoiceid));
  84. while ($data = mysql_fetch_array($result)) {
  85. $invoiceitems[$invoiceid][] = array("id"=> $data['id'],"description" => nl2br($data['description']),"amount" => formatCurrency($data['amount']), "tax" => $data['tax']);
  86. }
  87. }
  88.  
  89. if($geninvoice) {
  90. foreach($xmasspays as $iid => $vals) {
  91. update_query("tblinvoices", array("status" => "Cancelled"), array("id" => $iid,"userid" => $client->getID()));
  92. }
  93. require("includes/processinvoices.php");
  94. $invoiceid =createInvoices($client->getID(), true, true);
  95. $result = select_query("tblpaymentgateways","value", array("gateway"=> $paymentmethod,"setting" => "type"));
  96. $data = mysql_fetch_array($result);
  97. $gatewaytype = $data['value'];
  98.  
  99. if($gatewaytype == "CC" || $gatewaytype == "OfflineCC") {
  100. if(!isValidforPath($paymentmethod)) {
  101. exit("Invalid Payment Gateway Name");
  102. }
  103. $gatewaypath = ROOTDIR."/modules/gateways/".$paymentmethod.".php";
  104. if (file_exists($gatewaypath)) {
  105. require_once($gatewaypath);
  106. }
  107. if (!function_exists($paymentmethod."_link")) {
  108. header("Location: creditcard.php?invoiceid=".$invoiceid);
  109. exit();
  110. }
  111. }
  112.  
  113. $result = select_query("tblinvoices", "", array("userid" => $client->getID(), "id" => $invoiceid));
  114. $data = mysql_fetch_array($result);
  115. $id = $data['id'];
  116. $total = $data['total'];
  117. $paymentmethod = $data['paymentmethod'];
  118. $clientsdetails = getClientsDetails($client->getID());
  119. $params = getGatewayVariables($paymentmethod, $id, $total);
  120. $paymentbutton = call_user_func($paymentmethod."_link",$params);
  121. $ca->setTemplate("forwardpage");
  122. $ca->assign("message", $_LANG['forwardingtogateway']);
  123. $ca->assign("code", $paymentbutton);
  124. $ca->assign("invoiceid",$id);
  125. $ca->output();
  126. exit();
  127. }
  128. $smartyvalues['subtotal'] = formatCurrency($subtotal);
  129. if($credit) {
  130. $smartyvalues['credit'] = formatCurrency($credit);
  131. }
  132. if($tax) {
  133. $smartyvalues['tax'] = formatCurrency($tax);
  134. }
  135. if ($tax2) {
  136. $smartyvalues['tax2'] = formatCurrency($tax2);
  137. }
  138. if ($partialpayments) {
  139. $smartyvalues['partialpayments'] = formatCurrency($partialpayments);
  140. }
  141. $smartyvalues['total'] = formatCurrency($total - $partialpayments);
  142. $smartyvalues['invoiceitems'] = $invoiceitems;
  143. $gatewayslist = showPaymentGatewaysList();
  144. $smartyvalues['gateways'] = $gatewayslist;
  145. $smartyvalues['defaultgateway'] = key($gatewayslist);
  146. }
Advertisement
Add Comment
Please, Sign In to add comment