<?php
/****************************************
/*  Author 	: Kvvaradha
/*  Module 	: Kvcodes CRM
/*  E-mail 	: admin@kvcodes.com
/*  Version : 1.0
/*  Http 	: www.kvcodes.com
*****************************************/

$page_security = 'SA_OPEN';
$path_to_root="..";

include($path_to_root . "/modules/KvcodesCRM/includes/crm.inc" );
global $reports;

define('RC_KVCODESCRM', 11);

$reports->register_controls('CRM_Reports');

function CRM_Reports($name, $type){
    switch($type){

		case 'PROPOSALS': 
			$sql = "SELECT sorder.order_no, IF(`sorder`.`formType` = 1, CONCAT(sorder.order_no, '-', `lead`.`first_name`, `lead`.`last_name`), debtor.name ) AS IName
				FROM ".TB_PREF."kv_crm_sales_orders sorder
				LEFT JOIN ".TB_PREF."debtors_master AS debtor ON `debtor`.`debtor_no` = `sorder`.`debtor_no` LEFT JOIN ".TB_PREF."kv_crm_leads AS lead ON `lead`.`lead_id` = `sorder`.`debtor_no` WHERE debtor.debtor_no=sorder.debtor_no	AND sorder.trans_type=".ST_SALESPROPOSAL
					." ORDER BY sorder.order_no DESC";
			return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
			
		case 'INVOICES': 
			$sql = "SELECT sorder.order_no, concat(sorder.order_no, '-', debtor.name) as IName	FROM ".TB_PREF."kv_crm_sales_orders sorder,
			".TB_PREF."debtors_master debtor  WHERE debtor.debtor_no=sorder.debtor_no	AND sorder.trans_type=".ST_PROJECTINVOICE." ORDER BY sorder.order_no DESC";
			return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
			
		case 'ESTIMATES' :
			$sql = "SELECT sorder.order_no, concat(sorder.order_no, '-', debtor.name) as IName	FROM ".TB_PREF."kv_crm_sales_orders sorder,
				".TB_PREF."debtors_master debtor  WHERE debtor.debtor_no=sorder.debtor_no	AND sorder.trans_type=".ST_SALESESTIMATE." ORDER BY sorder.order_no DESC";
			return combo_input($name, '', $sql, 'order_no', 'IName',array('order'=>false));
	}
}

$reports->addReportClass(_("CRM Reports"), RC_KVCODESCRM);

$reports->addReport(RC_KVCODESCRM, 120, _('Print Estimates'),
       array( _('From') => 'ESTIMATES',
			_('To') => 'ESTIMATES',
			_('Currency Filter') => 'CURRENCY',
			_('Email Customers') => 'YES_NO',
			_('Comments') => 'TEXTBOX',
			_('Orientation') => 'ORIENTATION'));
    $reports->addReport(RC_KVCODESCRM, 121, _('Print Proposal'),
       array( _('From') => 'PROPOSALS',
			_('To') => 'PROPOSALS',
			_('Currency Filter') => 'CURRENCY',
			_('Email Customers') => 'YES_NO',
			_('Comments') => 'TEXTBOX',
			_('Orientation') => 'ORIENTATION'));
	$reports->addReport(RC_KVCODESCRM, 122, _('Print Project Invoice'),
       array( _('From') => 'INVOICES',
			_('To') => 'INVOICES',
			_('Currency Filter') => 'CURRENCY',
			_('Email Customers') => 'YES_NO',
			_('Comments') => 'TEXTBOX',
			_('Orientation') => 'ORIENTATION'));
			
