Changeset 2743

Show
Ignore:
Timestamp:
02/13/10 17:39:08 (2 years ago)
Author:
rach
Message:

Fix payment of an unpaid subscription

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/customer/checkout_process.php

    r2742 r2743  
    436436                                        } 
    437437                                        if($item -> getExtType() == 'SUBSCR'){ 
    438                                                 $QUERY = "UPDATE cc_card_subscription SET paid_status = 2 WHERE id=" . $item -> getExtId(); 
    439                                                 $instance_table->SQLExec($DBHandle, $QUERY, 0); 
     438                                                //Load subscription 
     439                                                $table_subsc = new Table('cc_card_subscription','paid_status'); 
     440                                                $subscr_clause = "id = ".$item -> getExtId(); 
     441                                                $result_subscr = $table_subsc -> Get_list($DBHandle,$subscr_clause); 
     442                                                if(is_array($result_subscr)){ 
     443                                                        $subscription = $result_subscr[0]; 
     444                                                        if($subscription['paid_status']==3){ 
     445                                                                $billdaybefor_anniversery = $A2B->config['global']['subscription_bill_days_before_anniversary']; 
     446                                                                $unix_startdate = time(); 
     447                                                                $startdate = date("Y-m-d",$unix_startdate); 
     448                                                                $day_startdate = date("j",$unix_startdate); 
     449                                                                $month_startdate = date("m",$unix_startdate); 
     450                                                                $year_startdate= date("Y",$unix_startdate); 
     451                                                                $lastday_of_startdate_month = lastDayOfMonth($month_startdate,$year_startdate,"j"); 
     452 
     453                                                                $next_bill_date = strtotime("01-$month_startdate-$year_startdate + 1 month"); 
     454                                                                $lastday_of_next_month= lastDayOfMonth(date("m",$next_bill_date),date("Y",$next_bill_date),"j"); 
     455 
     456                                                                if ($day_startdate > $lastday_of_next_month) { 
     457                                                                        $next_limite_pay_date = date ("$lastday_of_next_month-m-Y" ,$next_bill_date); 
     458                                                                } else { 
     459                                                                $next_limite_pay_date = date ("$day_startdate-m-Y" ,$next_bill_date); 
     460                                                                } 
     461 
     462                                                                $next_bill_date = date("Y-m-d",strtotime("$next_limite_pay_date - $billdaybefor_anniversery day")) ; 
     463                                                                $QUERY = "UPDATE cc_card SET status = 1 WHERE id=" . $id; 
     464                                                                $result = $instance_table->SQLExec($A2B->DBHandle, $QUERY, 0); 
     465                                                                $QUERY = "UPDATE cc_card_subscription SET paid_status = 2, startdate = '$startdate' ,limit_pay_date = '$next_limite_pay_date',  next_billing_date ='$next_bill_date' WHERE id=" . $item -> getExtId(); 
     466                                                                $instance_table->SQLExec($DBHandle, $QUERY, 0); 
     467                                                        }else{ 
     468                                                                $QUERY = "UPDATE cc_card_subscription SET paid_status = 2 WHERE id=". $item -> getExtId(); 
     469                                                                $instance_table->SQLExec($DBHandle, $QUERY, 0); 
     470                                                        } 
     471                                                } 
    440472                                        } 
    441473                                }