Jump to content

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


kabucek

Recommended Posts

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             

                 

Link to comment
Share on other sites

hi...

to many lines mean you will have more correctly and better understand what logic u type

 

don't say to many.. because i don't see this script as worse as you said.

 

what i suggest here.. u should type the script with better

 

btw.. how about this

$Today and $done=0=date('m/d/y');
$done=0;
if  ($selectedProdCode="agreem" and $errorArray['agr1expdate'] < $Today and $done=0)
{
$selectedProdCode=// code with 1 agr and late fee
$done=1;
}

if  ( $selectedProdCode="agreem" and $errorArray['agr1expdate'] > $Today and $done=0)
{
    $selectedProdCode=// code with 1 agr and no late fee
    $done=1;
}

if ($selectedProdCode="agreem" and $errorArray['agr1expdate'] < $Today and $done=0)
{
$selectedProdCode=// code with 1 agr and late fee
$done=1;
}

if ($selectedProdCode="agreem" and $errorArray['agr1expdate'] == $Today and $done=0)
{
$selectedProdCode=// code with 1 agr and no late fee
$done=1;
}
                   

if ( $selectedProdCode="agreem2" and $errorArray['agr1expdate'] == $Today and $done=0 and $errorArray['agr2expdate'] == $Today and $done=0 )
{
$selectedProdCode=// code with 2 certs and no late fee
$done=1;
}

if ($selectedProdCode="agreem2" and $errorArray['agr1expdate'] > $Today and $done=0 and $errorArray['agr2expdate'] > $Today and $done=0
{
$selectedProdCode=// code with 2 agr and no late fee
    $done=1;
}

if ($selectedProdCode="agreem2" and $errorArray['agr1expdate'] == $Today and $done=0 and $errorArray['agr2expdate'] > $Today and $done=0
{
$selectedProdCode=// code with 2 agr and no late fee
$done=1;
}

if ($selectedProdCode="agreemn2" and $errorArray['agr1expdate'] > $Today and $done=0 and $errorArray['agr2expdate'] == $Today and $done=0
{
$selectedProdCode=// code with 2 certs and no late fee
$done=1;
}

if ($selectedProdCode="agreem2" and $errorArray['agr1expdate'] < $Today and $done=0 and $errorArray['agr2expdate'] == $Today and $done=0
{
selectedProdCode=// code with 2 certs and plus 1x late fee
$done=1;
}

if ($selectedProdCode="agreem2" and $errorArray['agr1expdate'] == $Today and $done=0 and $errorArray['agr2expdate'] < $Today and $done=0
{
$selectedProdCode=// code with 2 agr and plus 1x late fee
$done=1;
}

if ($selectedProdCode="agreem2" and $errorArray['agr1expdate'] < $Today and $done=0 and $errorArray['agr2expdate'] > $Today and $done=0
{
$selectedProdCode=// code with 2 certs and plus 1x late fee
$done=1;
}

if ($selectedProdCode="agreem2" and $errorArray['agr1expdate'] > $Today and $done=0 and $errorArray['agr2expdate'] < $Today and $done=0
{
$selectedProdCode=// code with 2 agr and plus 1x late fee
$done=1;
}
                   
     

what the different with you script

*point the $done

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.