[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/Invoice/ -> InvoiceHandler.php (source)

   1  <?php
   2  
   3  /* +***********************************************************************************

   4   * The contents of this file are subject to the vtiger CRM Public License Version 1.0

   5   * ("License"); You may not use this file except in compliance with the License

   6   * The Original Code is:  vtiger CRM Open Source

   7   * The Initial Developer of the Original Code is vtiger.

   8   * Portions created by vtiger are Copyright (C) vtiger.

   9   * All Rights Reserved.

  10   * *********************************************************************************** */
  11  include_once  'include/Webservices/Revise.php';
  12  include_once  'include/Webservices/Retrieve.php';
  13  
  14  class InvoiceHandler extends VTEventHandler {
  15  
  16      function handleEvent($eventName, $entityData) {
  17  
  18          $moduleName = $entityData->getModuleName();
  19  
  20          // Validate the event target

  21          if ($moduleName != 'Invoice') {
  22              return;
  23          }
  24  
  25          //Get Current User Information

  26          global $current_user, $currentModule;
  27  
  28          /**

  29           * Adjust the balance amount against total & received amount

  30           * NOTE: beforesave the total amount will not be populated in event data.

  31           */
  32          if ($eventName == 'vtiger.entity.aftersave') {
  33              // Trigger from other module (due to indirect save) need to be ignored - to avoid inconsistency.

  34              if ($currentModule != 'Invoice')
  35                  return;
  36              $entityDelta = new VTEntityDelta();
  37              $oldCurrency = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
  38              $newCurrency = $entityDelta->getCurrentValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
  39              $oldConversionRate = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'conversion_rate');
  40              $db = PearDatabase::getInstance();
  41              $wsid = vtws_getWebserviceEntityId('Invoice', $entityData->getId());
  42              $wsrecord = vtws_retrieve($wsid,$current_user);
  43              if ($oldCurrency != $newCurrency && $oldCurrency != '') {
  44                if($oldConversionRate != ''){ 
  45                  $wsrecord['received'] = floatval(($wsrecord['received']/$oldConversionRate) * $wsrecord['conversion_rate']);
  46                }  
  47              }
  48              $wsrecord['balance'] = floatval($wsrecord['hdnGrandTotal'] - $wsrecord['received']);
  49              if ($wsrecord['balance'] == 0) {
  50                  $wsrecord['invoicestatus'] = 'Paid';
  51              }
  52              $query = "UPDATE vtiger_invoice SET balance=?,received=? WHERE invoiceid=?";
  53              $db->pquery($query, array($wsrecord['balance'], $wsrecord['received'], $entityData->getId()));
  54          }
  55      }
  56  
  57  }
  58  
  59  ?>


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1