/**
  * Saving configuration in .conf file
  *
  */
 static function saveConf()
 {
     $configFile = fopen(dirname(__FILE__) . '/facturacom.conf', 'w') or die('Unable to open file!');
     //write apiKey
     fwrite($configFile, WrapperHelper::strEncode(self::$apiKey) . "\n");
     //write apiSecret
     fwrite($configFile, WrapperHelper::strEncode(self::$apiSecret) . "\n");
     //write serie
     fwrite($configFile, WrapperHelper::strEncode(self::$serie) . "\n");
     //write dayOff
     fwrite($configFile, WrapperHelper::strEncode(self::$dayOff) . "\n");
     //write activateDay
     fwrite($configFile, WrapperHelper::strEncode(self::$activateDate) . "\n");
     //write apiUrl
     fwrite($configFile, WrapperHelper::strEncode(self::$apiUrl) . "\n");
     //write version
     fwrite($configFile, WrapperHelper::strEncode(self::$version) . "\n");
     //write access
     fwrite($configFile, WrapperHelper::strEncode(self::$access) . "\n");
     //write systemURL
     fwrite($configFile, WrapperHelper::strEncode(self::$systemURL) . "\n");
     //write iva
     fwrite($configFile, WrapperHelper::strEncode(self::$iva));
     fclose($configFile);
 }
 /**
  * Get WHMCS orders or orders by filter
  *
  * @param Int $clientId
  * @return Object
  */
 static function getWhmcsInvoices($clientId)
 {
     if (!isset($clientId)) {
         return array('Error' => 'No se ha recibido el id del cliente.');
     }
     $invoiceList = array();
     $facturaInvoiceList = array();
     $invoicesObj = Capsule::table('tblinvoices')->where('tblinvoices.userid', $clientId)->get();
     foreach ($invoicesObj as $key => $value) {
         $invoiceList[$value->id]["orderId"] = $value->id;
         $invoiceList[$value->id]["orderNum"] = $value->id;
         $invoiceList[$value->id]["clientId"] = $value->userid;
         $invoiceList[$value->id]["orderDate"] = date("d-m-Y", strtotime($value->date));
         $invoiceList[$value->id]["invoiceDueDate"] = date("d-m-Y", strtotime($value->duedate));
         $invoiceList[$value->id]["invoiceDatePaid"] = !preg_match('/[1-9]/', $value->datepaid) ? NULL : date("d-m-Y", strtotime($value->datepaid));
         $invoiceList[$value->id]["total"] = $value->total;
         $invoiceList[$value->id]["status"] = $value->status;
         $invoiceList[$value->id]["orderdata"] = self::getInvoiceItems($value->id);
         $invoiceList[$value->id]["sent"] = false;
         $invoiceList[$value->id]["open"] = true;
         if ($value->status != "Paid") {
             $invoiceList[$value->id]["open"] = false;
         }
         // open
         /* validar que la factura esté dentro del mes +X días y a partir
                de la fecha de facturación configurada
            */
         $order_month = date("m", strtotime($value->datepaid));
         $order_year = date("Y", strtotime($value->datepaid));
         $current_day = date("d");
         $current_month = date("m");
         $current_year = date("Y");
         $configEntity = WrapperConfig::configEntity();
         if (!WrapperConfig::issetConfig($configEntity)) {
             $invoiceList[$value->id]["open"] = false;
         }
         $arr = explode('/', $configEntity['activateDate']);
         /* formatear la fecha a dd-mm-aaaa porque la fecha datepaid
            tiene ese formato en WHMCS y deben tener el mismo formato para
            compararse. */
         $newDate = $arr[0] . '-' . $arr[1] . '-' . $arr[2];
         $activateDate = strtotime($newDate);
         //1 septiembre 2015
         $paidDate = strtotime($value->datepaid);
         //6 Octubre 2015
         // Validate plugin activation date vs payment date
         if ($paidDate < $activateDate) {
             $invoiceList[$value->id]["open"] = false;
         }
         // Validate payment date vs current date
         if ($order_month != $current_month) {
             $order_day = date("d", strtotime($value->datepaid));
             if ($order_month < $current_month) {
                 if (intval($current_day) > $configEntity['dayOff']) {
                     $invoiceList[$value->id]["open"] = false;
                 }
                 if ($order_month == 12) {
                     $order_year += 1;
                 }
             } elseif ($order_year < $current_year) {
                 $invoiceList[$value->id]["open"] = false;
             }
         }
     }
     $facturaInvoices = WrapperHelper::getInvoices($clientId)->data;
     foreach ($facturaInvoices as $key => $value) {
         $facturaInvoiceList[$value->NumOrder] = $value;
         if (array_key_exists($value->NumOrder, $invoiceList)) {
             $invoiceList[$value->NumOrder]["sent"] = true;
         }
     }
     $collection = array_diff_key($invoiceList, $facturaInvoiceList);
     return $collection;
 }
//define("FORCESSL", true); // Uncomment to force the page to use https://
require "init.php";
require 'modules/addons/facturacom/wrapperapp.php';
$ca = new WHMCS_ClientArea();
$ca->setPageTitle("Facturación de servicios");
$ca->initPage();
$ca->requireLogin();
if ($ca->isLoggedIn()) {
    WrapperConfig::load();
    $configEntity = WrapperConfig::configEntity();
    // Getting invoices by client from factura.com
    $invoices = (array) WrapperHelper::getInvoices($ca->getUserID());
    $clientInvoices = array();
    //object to array
    foreach ($invoices['data'] as $key => $value) {
        $clientInvoices[$key] = (array) $value;
    }
    // Getting invoices from whmcs
    $whmcsInvoices = WrapperHelper::getWhmcsInvoices($ca->getUserID());
    $ca->assign('clientW', $ca->getUserID());
    $ca->assign('whmcsInvoices', $whmcsInvoices);
    $ca->assign('clientInvoices', $clientInvoices);
    $ca->assign('systemURL', $configEntity['systemURL']);
    $ca->assign('apiUrl', $configEntity['apiUrl']);
    $ca->assign('serieInvoices', $configEntity['serie']);
} else {
    # User is not logged in
}
# Define the template filename to be used without the .tpl extension
$ca->setTemplate('customer_area/clientfacturacion');
$ca->output();
Beispiel #4
0
<?php

$invoices = WrapperHelper::getInvoices();
$index = 0;
$configEntity = WrapperConfig::configEntity();
$systemURL = $configEntity['systemURL'];
?>
<style media="screen">
    .label-danger {
        background-color: #d9534f;
    }
    .label-success {
        background-color: #5cb85c;
    }
    table.dataTable thead th {
        background-image: url("../images/sort_asc.png");
        background-color: #2A5E90;
        color: #FFFFFF;
    }
    .dataTables_wrapper .dataTables_paginate .paginate_button.current,
    .dataTables_wrapper .dataTables_paginate .paginate_button.current:hover,
    .dataTables_wrapper .dataTables_paginate .paginate_button:hover{
        background: #2A5E90;
        color: #FFFFFF !important;
        border-color: #46b8da;
    }
</style>
<input type="hidden" id="systemURL" value="<?php 
echo $systemURL;
?>
" />
/**
 * Update client information and create Invoice
 *
 * @param Global $_POST
 * @return Array
 */
function createInvoice()
{
    $orderNum = $_POST['orderNum'];
    $orderItems = $_POST['orderItems'];
    $clientData = $_POST['clientData'];
    $invoideData = json_decode($clientData[18]["value"]);
    $serieInvoices = $_POST['serieInvoices'];
    $clientW = $_POST['clientW'];
    $paymentMethod = $_POST['paymentMethod'];
    $numerocuenta = $_POST['numerocuenta'];
    return WrapperHelper::createInvoice($orderNum, $orderItems, $clientData, $serieInvoices, $clientW, $paymentMethod, $numerocuenta);
}