<?php

/* vim: set expandtab tabstop=4 shiftwidth=4 softtabstop=4: 			*/

// +----------------------------------------------------------------------+

// | PHP version 4/5                                                      |

// +----------------------------------------------------------------------+

// | Copyright (c) 2004-2010 ARMIA INC                                    |

// +----------------------------------------------------------------------+

// | This source file is a part of iScripts VistaCart                     |

// +----------------------------------------------------------------------+

// | Authors: Jipson<jipson.thomas@armiasystems.com>             		  |

// +----------------------------------------------------------------------+

class Coupon extends AppModel

{

   	var $name = 'Coupon';	

	 function checkeditDups($cpncode,$editid){

   		$Db = ConnectionManager::getDataSource($this->useDbConfig);

		$cpntbl = $Db->fullTableName('coupons');	

		$res=$this->query("SELECT count(*)  as dups from $cpntbl WHERE `code` ='".$cpncode."' and `id`<>".$editid);

		return $res[0][0]["dups"];

		}

     /*
     * Function to coupon Details
     */
    function getCouponDetails($couponCode){

        $Db = ConnectionManager::getDataSource($this->useDbConfig);

        $cTbl = $Db->fullTableName('coupons');
              
        $sel = "SELECT c.id, c.code, c.type, c.giftvalue, c.from_date, c.to_date, c.status, c.descr, c.minamt, (CASE WHEN DATEDIFF(CURDATE(), DATE(c.to_date))<=0 THEN 0 ELSE 1 END) as expired FROM $cTbl c WHERE BINARY c.code = '".$couponCode."'";
      
        $dataArr = $this->query($sel);

        return $dataArr;
    } // End Function

}

?>