Re: how to simplify my code - I will have tooo many lines -please help

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



kabucek1 wrote:
> hi all,
> 
> I have form in which people renew their agreements online.
> they can renew up to 5 agreements.
> I need to check if the expiration date is older than today, late fee will be
> added.
> if exp. date is equal or newer - no late fee.
> I have something like this so far and I can go further with this
> but my question is, if there is a way to simplify this code a little bit,
> or to make it shorter?
> 
> 
>  $Today=date('m/d/y');
> 
>  if  ($selectedProdCode="agreem" and $errorArray['agr1expdate'] < $Today)
>           {
>             $selectedProdCode=// code with 1 agr and late fee
>             }
>            else {    //1 agr
>                   if  ( $selectedProdCode="agreem" and
> $errorArray['agr1expdate'] > $Today)
>                     {
>                       $selectedProdCode=// code with 1 agr and no late fee
>                     }
>                  else
>                   {
>                         if ($selectedProdCode="agreem" and
> $errorArray['agr1expdate'] < $Today)
>                         {
>                            $selectedProdCode=// code with 1 agr and late fee
>                         }
>                    }
>                  else
>                   {
>                         if ($selectedProdCode="agreem" and
> $errorArray['agr1expdate'] == $Today)
>                         {
>                            $selectedProdCode=// code with 1 agr and no late
> fee
>                         }
>                    }
>                    
>               
> /////------------------------------------------------------------------------------------------------------
>                    //2 agr
>                      else
>                   {
>                         if ( $selectedProdCode="agreem2" and
> $errorArray['agr1expdate'] == $Today and $errorArray['agr2expdate'] ==
> $Today )
>                         {
>                            $selectedProdCode=// code with 2 certs and no
> late fee
>                         }
>                    }
> 
>                    else
>                   {
>                         if ($selectedProdCode="agreem2" and
> $errorArray['agr1expdate'] > $Today and $errorArray['agr2expdate'] > $Today
>                         {
>                            $selectedProdCode=// code with 2 agr and no late
> fee
>                         }
>                    }
>                    
>                    else
>                   {
>                         if ($selectedProdCode="agreem2" and
> $errorArray['agr1expdate'] == $Today and $errorArray['agr2expdate'] > $Today
>                         {
>                            $selectedProdCode=// code with 2 agr and no late
> fee
>                         }
>                    }
>                    
>                    else
>                   {
>                         if ($selectedProdCode="agreemn2" and
> $errorArray['agr1expdate'] > $Today and $errorArray['agr2expdate'] == $Today
>                         {
>                            $selectedProdCode=// code with 2 certs and no
> late fee
>                         }
>                    }
>                    
>                    else
>                   {
>                         if ($selectedProdCode="agreem2" and
> $errorArray['agr1expdate'] < $Today and $errorArray['agr2expdate'] == $Today
>                         {
>                            $selectedProdCode=// code with 2 certs and plus
> 1x late fee
>                         }
>                    }
> 
>                    else
>                   {
>                         if ($selectedProdCode="agreem2" and
> $errorArray['agr1expdate'] == $Today and $errorArray['agr2expdate'] < $Today
>                         {
>                            $selectedProdCode=// code with 2 agr and plus 1x
> late fee
>                         }
>                    }
>                    
>                    else
>                   {
>                         if ($selectedProdCode="agreem2" and
> $errorArray['agr1expdate'] < $Today and $errorArray['agr2expdate'] > $Today
>                         {
>                            $selectedProdCode=// code with 2 certs and plus
> 1x late fee
>                         }
>                    }
>                    
>                    else
>                   {
>                         if ($selectedProdCode="agreem2" and
> $errorArray['agr1expdate'] > $Today and $errorArray['agr2expdate'] < $Today
>                         {
>                            $selectedProdCode=// code with 2 agr and plus 1x
> late fee
>                         }
>                    }
>                    
>      
> 
> 
> 
> Thanks              
>                    
Wow!  Yes, there are a lot of ways to do it.  This is a quick stab (not
tested):

$Today = date('m/d/y');

if ( $selectedProdCode="agreem" && $errorArray['agr1expdate'] < $Today)
{
	$selectedProdCode= //agreement cost + late fee
} else {
	$selectedProdCode= //agreement cost
}
if ( $selectedProdCode="agreem2" && $errorArray['agr1expdate'] >= $Today
&& $errorArray['agr2expdate'] >= $Today )
{	
	$selectedProdCode= //agreement cost * 2
}
elseif ( $selectedProdCode="agreem2" && ($errorArray['agr1expdate'] <
$Today || $errorArray['agr2expdate'] < $Today) )
{	
	if ( $errorArray['agr1expdate'] < $Today && $errorArray['agr2expdate']
< $Today )
	{
		$selectedProdCode= //(agreement cost * 2) + (late fee *2)
	} else {
		$selectedProdCode= //(agreement cost * 2) + late fee
	}		
}

-- 
Thanks!
-Shawn
http://www.spidean.com

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux