[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/modules/PurchaseOrder/ -> PurchaseOrderHandler.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 PurchaseOrderHandler extends VTEventHandler {
  15  
  16      function handleEvent($eventName, $entityData) {
  17  
  18          $moduleName = $entityData->getModuleName();
  19  
  20  
  21          // Validate the event target

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

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

  30           * Adjust the balance amount against total & paid amount

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

  32           */
  33          if ($eventName == 'vtiger.entity.aftersave') {
  34              if ($currentModule != 'PurchaseOrder')
  35                  return;
  36              $entityDelta = new VTEntityDelta();
  37              $oldCurrency = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
  38              $oldConversionRate = $entityDelta->getOldValue($entityData->getModuleName(), $entityData->getId(), 'conversion_rate');
  39              $newCurrency = $entityDelta->getCurrentValue($entityData->getModuleName(), $entityData->getId(), 'currency_id');
  40              $db = PearDatabase::getInstance();
  41              $wsid = vtws_getWebserviceEntityId('PurchaseOrder', $entityData->getId());
  42              $wsrecord = vtws_retrieve($wsid,$current_user);
  43              if ($oldCurrency != $newCurrency && $oldCurrency != '') {
  44                  if($oldConversionRate != ''){
  45                      $wsrecord['paid'] = floatval(($wsrecord['paid']/$oldConversionRate) * $wsrecord['conversion_rate']);
  46                  } 
  47              }
  48              $wsrecord['balance'] = floatval($wsrecord['hdnGrandTotal'] - $wsrecord['paid']);
  49              if ($wsrecord['balance'] == 0)
  50                  $wsrecord['postatus'] = 'Received Shipment';
  51              $query = "UPDATE vtiger_purchaseorder SET balance=?,paid=? WHERE purchaseorderid=?";
  52              $db->pquery($query, array($wsrecord['balance'], $wsrecord['paid'], $entityData->getId()));
  53              // TODO Make it available for other event handlers

  54          }
  55      }
  56  
  57  }
  58  
  59  ?>


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