Exemplo n.º 1
0
 public function getInvoices($criteria = array())
 {
     global $aInt;
     global $currency;
     $query = " FROM tblinvoices INNER JOIN tblclients ON tblclients.id=tblinvoices.userid";
     $filters = $this->buildCriteria($criteria);
     $query .= count($filters) ? " WHERE " . implode(" AND ", $filters) : "";
     $result = full_query("SELECT COUNT(*)" . $query);
     $data = mysql_fetch_array($result);
     $this->getPageObj()->setNumResults($data[0]);
     $gateways = new WHMCS_Gateways();
     $orderby = $this->getPageObj()->getOrderBy();
     if ($orderby == "clientname") {
         $orderby = "firstname " . $this->getPageObj()->getSortDirection() . ",lastname " . $this->getPageObj()->getSortDirection() . ",companyname";
     }
     if ($orderby == "id") {
         $orderby = "tblinvoices.invoicenum " . $this->getPageObj()->getSortDirection() . ",tblinvoices.id";
     }
     $invoices = array();
     $query = "SELECT tblinvoices.*,tblclients.firstname,tblclients.lastname,tblclients.companyname,tblclients.groupid,tblclients.currency" . $query . " ORDER BY " . $orderby . " " . $this->getPageObj()->getSortDirection() . " LIMIT " . $this->getQueryLimit();
     $result = full_query($query);
     while ($data = mysql_fetch_array($result)) {
         $id = $data['id'];
         $invoicenum = $data['invoicenum'];
         $userid = $data['userid'];
         $date = $data['date'];
         $duedate = $data['duedate'];
         $subtotal = $data['subtotal'];
         $credit = $data['credit'];
         $total = $data['total'];
         $gateway = $data['paymentmethod'];
         $status = $data['status'];
         $firstname = $data['firstname'];
         $lastname = $data['lastname'];
         $companyname = $data['companyname'];
         $groupid = $data['groupid'];
         $currency = $data['currency'];
         $clientname = $aInt->outputClientLink($userid, $firstname, $lastname, $companyname, $groupid);
         $paymentmethod = $gateways->getDisplayName($gateway);
         $currency = getCurrency("", $currency);
         $totalformatted = formatCurrency($credit + $total);
         $statusformatted = $this->formatStatus($status);
         $date = fromMySQLDate($date);
         $duedate = fromMySQLDate($duedate);
         if (!$invoicenum) {
             $invoicenum = $id;
         }
         $invoices[] = array("id" => $id, "invoicenum" => $invoicenum, "userid" => $userid, "clientname" => $clientname, "date" => $date, "duedate" => $duedate, "subtotal" => $subtotal, "credit" => $credit, "total" => $total, "totalformatted" => $totalformatted, "gateway" => $gateway, "paymentmethod" => $paymentmethod, "status" => $status, "statusformatted" => $statusformatted);
     }
     return $invoices;
 }
Exemplo n.º 2
0
 public function getOrders($criteria = array())
 {
     global $aInt;
     global $currency;
     $query = "FROM tblorders INNER JOIN tblclients ON tblclients.id=tblorders.userid";
     if ($criteria['paymentstatus']) {
         $query .= " INNER JOIN tblinvoices ON tblinvoices.id=tblorders.invoiceid";
     }
     $filters = $this->buildCriteria($criteria);
     if (count($filters)) {
         $query .= " WHERE " . implode(" AND ", $filters);
     }
     $result = full_query("SELECT COUNT(tblorders.id) " . $query);
     $data = mysql_fetch_array($result);
     $this->getPageObj()->setNumResults($data[0]);
     $query .= " ORDER BY tblorders." . $this->getPageObj()->getOrderBy() . " " . $this->getPageObj()->getSortDirection();
     $gateways = new WHMCS_Gateways();
     $invoices = new WHMCS_Invoices();
     $orders = array();
     $query = "SELECT tblorders.id,tblorders.ordernum,tblorders.userid,tblorders.date,tblorders.amount,tblorders.paymentmethod,tblorders.status,tblorders.invoiceid,tblorders.ipaddress,tblclients.firstname,tblclients.lastname,tblclients.companyname,tblclients.groupid,tblclients.currency,(SELECT status FROM tblinvoices WHERE id=tblorders.invoiceid) AS invoicestatus " . $query . " LIMIT " . $this->getQueryLimit();
     $result = full_query($query);
     while ($data = mysql_fetch_array($result)) {
         $id = $data['id'];
         $ordernum = $data['ordernum'];
         $userid = $data['userid'];
         $date = $data['date'];
         $amount = $data['amount'];
         $gateway = $data['paymentmethod'];
         $status = $data['status'];
         $invoiceid = $data['invoiceid'];
         $firstname = $data['firstname'];
         $lastname = $data['lastname'];
         $companyname = $data['companyname'];
         $groupid = $data['groupid'];
         $currency = $data['currency'];
         $ipaddress = $data['ipaddress'];
         $invoicestatus = $data['invoicestatus'];
         $date = fromMySQLDate($date, 1);
         $paymentmethod = $gateways->getDisplayName($gateway);
         $statusformatted = $this->formatStatus($status);
         if ($invoiceid == "0") {
             $paymentstatus = "<span class=\"textgreen\">" . $aInt->lang("orders", "noinvoicedue") . "</span>";
         } else {
             if (!$invoicestatus) {
                 $paymentstatus = "<span class=\"textred\">Invoice Deleted</span>";
             } else {
                 if ($invoicestatus == "Paid") {
                     $paymentstatus = "<span class=\"textgreen\">" . $aInt->lang("status", "complete") . "</span>";
                 } else {
                     if ($invoicestatus == "Unpaid") {
                         $paymentstatus = "<span class=\"textred\">" . $aInt->lang("status", "incomplete") . "</span>";
                     } else {
                         $paymentstatus = $invoices->formatStatus($invoicestatus);
                     }
                 }
             }
         }
         $currency = getCurrency("", $currency);
         $amount = formatCurrency($amount);
         $clientname = $aInt->outputClientLink($userid, $firstname, $lastname, $companyname, $groupid);
         $orders[] = array("id" => $id, "ordernum" => $ordernum, "date" => $date, "clientname" => $clientname, "gateway" => $gateway, "paymentmethod" => $paymentmethod, "amount" => $amount, "paymentstatus" => strip_tags($paymentstatus), "paymentstatusformatted" => $paymentstatus, "status" => $status, "statusformatted" => $statusformatted);
     }
     return $orders;
 }