403Webshell
Server IP : 138.197.176.125  /  Your IP : 216.73.216.41
Web Server : Apache/2.4.41 (Ubuntu)
System : Linux SuiteCRM-8 5.4.0-216-generic #236-Ubuntu SMP Fri Apr 11 19:53:21 UTC 2025 x86_64
User : root ( 0)
PHP Version : 8.3.19
Disable Function : NONE
MySQL : OFF  |  cURL : ON  |  WGET : ON  |  Perl : ON  |  Python : ON  |  Sudo : ON  |  Pkexec : ON
Directory :  /var/www/crest/modules/SalesOrder/

Upload File :
current_dir [ Writeable ] document_root [ Writeable ]

 

Command :


[ Back ]     

Current File : /var/www/crest/modules/SalesOrder/RecurringInvoiceHandler.php
<?php
/*********************************************************************************
  ** The contents of this file are subject to the vtiger CRM Public License Version 1.0
   * ("License"); You may not use this file except in compliance with the License
   * The Original Code is:  vtiger CRM Open Source
   * The Initial Developer of the Original Code is vtiger.
   * Portions created by vtiger are Copyright (C) vtiger.
   * All Rights Reserved.
  *
 ********************************************************************************/

require_once('include/utils/utils.php');

class RecurringInvoiceHandler extends VTEventHandler {
	
	private $entityData;
	
	public function handleEvent($handlerType, $entityData) {
		$this->entityData = $entityData;
	
		if ($this->isSalesOrderModule()) {
			$this->handleRecurringInvoiceGeneration();
		}
	}
	
	private function handleRecurringInvoiceGeneration() {
		if ($this->isRecurringInvoiceEnabled()) {
			if (empty($this->getNextInvoiceDate()) || $this->isStartDateAfterNextInvoiceDate()) {
				$this->setNextInvoiceDateEqualsToStartDate();
			}
		} else {
			$this->deleteRecurringInvoiceData();
		}
	}
	
	private function isStartDateAfterNextInvoiceDate()
	{
		$startPeriod = new DateTime($this->getStartDate());
		$nextInvoiceDate = new DateTime($this->getNextInvoiceDate());
		
		return $startPeriod > $nextInvoiceDate;
	}
	
	private function isSalesOrderModule() {
		return $this->entityData->getModuleName() == 'SalesOrder';
	}
	
	private function getStartDate()
	{
		$data = $this->entityData->getData();
		return DateTimeField::convertToDBFormat($data['start_period']);
	}
	
	private function getNextInvoiceDate() {
		$data = $this->entityData->getData();
		return $data['last_recurring_date'];
	}
	
	private function isRecurringInvoiceEnabled() {
		$data = $this->entityData->getData();
		return !empty($data['enable_recurring']);
	}
	
	private function setNextInvoiceDateEqualsToStartDate()
	{
		$db = PearDatabase::getInstance();
		$query = "UPDATE vtiger_invoice_recurring_info SET last_recurring_date = start_period WHERE salesorderid = ?";
		$db->pquery($query, [$this->entityData->getId()]);
	}
	
	private function deleteRecurringInvoiceData()
	{
		$db = PearDatabase::getInstance();
		$query = "DELETE FROM vtiger_invoice_recurring_info WHERE salesorderid = ?";
		$db->pquery($query, [$this->entityData->getId()]);	
	}
}

Youez - 2016 - github.com/yon3zu
LinuXploit