Thread Rating:
  • 2 Vote(s) - 3 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Billing cycle changes + Payment method plugin structure
#11
That is a nice piece of work. Has that actually been tied into the order form and works with the cron?
Jonny H - THT Main Developer & Founder


Reply
#12
This is already tied with the order form. And it works fine!
I'm currently modifying several things, like the currency management, package addons. I will add it to the cron when I have a stable code. I already create some tasks in google code for that.

(06-25-2010, 10:17 AM)Jonny Wrote: That is a nice piece of work. Has that actually been tied into the order form and works with the cron?
Reply
#13
(06-25-2010, 10:17 AM)Jonny Wrote: That is a nice piece of work. Has that actually been tied into the order form and works with the cron?

I finally manage to check and change the invoice->cron and there are some issues I want to ask/report:

1. I don't want to use the $server->terminate because is very dangerous. I mean deleting the user from the database is a bad thing as I said in this issue:
http://code.google.com/p/thehostingtool/...d=34&can=1
Should be better just to change the status to "deleted" or something like that. With this change it will be a good thing to "terminate" the user.

2. I see in that code that there are any warning notifications to the user before the due date expired. I think this will be a new feature.

3. I change the behaviour of that function to avoid the creation of invoices everytime you execute the cron and the date is expired.

4. Change many mysql_* function to the $db classes.

5. I added documentation for every step. (This is very important for new developers!!)

5. I change nosense variables like $array $array2 $array3.

6. I added my new billing cycle thing so the invoice->cron will not be hardcoded with a fixed value of 30 days.

7. In which case a user will not have a invoice?

8. Why there is not a order - invoice concept?
the user_pack could be a order table no?

This is a partial work don't be hard with me Big Grin

PHP Code:
public function cron(){
        global 
$db$server$billing ,$invoice;
        
$time time();
        
//For every package 
        
$query $db->query("SELECT * FROM `<PRE>packages` WHERE `type` = 'paid'");
        while(
$package $db->fetch_array($query)) {
            
$id intval($package['id']);
            
//For every user order
            
$result_user_packs $db->query("SELECT * FROM `<PRE>user_packs` WHERE `pid` = '{$id}'");
            while(
$user_pack $db->fetch_array($result_user_packs)) {
                
$uid intval($user_pack['userid']);
                
$result_invoices $db->query("SELECT * FROM `<PRE>invoices` WHERE `uid` = '{$uid}' ORDER BY id DESC LIMIT 1");
                
$billing_info      $billing->getBilling($user_pack['billing_cycle_id']);
                
//2592000 seconds = 30 days
                //If today is bigger than 30 days since the creation then create a new invoice
                
$number_months_in_seconds  intval($billing_info['number_months'])*30*24*60*60//Instead of 2592000 seconds = 30 days
                    
                
if($db->num_rows($result_invoices) > 0) {
                    
$my_invoice $db->fetch_array($result_invoices);
                                        
                    
//Generate a new invoice if time is exceed (first time)
                    //var_dump($time, strtotime($my_invoice['created']) + $number_months_in_seconds);
                    /*
                    echo 'Now : '.$today = date('Y-m-d h:i:s', time());
                    echo '<br />Invoice info :<br />';                    
                    echo 'Created date '.date('Y-m-d h:i:s', strtotime($my_invoice['created'])).'<br />';
                    echo 'Due date  '.date('Y-m-d h:i:s', $my_invoice['due']).'<br />';
                    */
                    //"Terminating" a user if he does not pay
                    
                    
$lastmonth             $time-2592000;
                    
$suspenddays         intval($db->config('suspensiondays'));
                    
$suspendseconds     $suspenddays*24*60*60;
                    
$terminateseconds     intval($db->config('terminationdays'))*24*60*60;
                    
                    
//If normal time is over and he does not paid
            //        var_dump(date('Y-m-d h:i:s',$time), date('Y-m-d h:i:s', strtotime($my_invoice['created']) + $number_months_in_seconds));
                    //If the package is paid 
                    //if ($package['paid']) {
                        
                    //1. Due date of the last invoice id has exceed
                    
if ($my_invoice['is_paid'] == 0) {
                        if (
$my_invoice['due'] < $time) {
                            
//My invoice has expired need to suspend if time has past the limits                        
                            //echo 'My invoice has expired need to suspend if time has past<br />';
                            
                            //Suspend conditions
                            //var_dump('Suspend : '.date('Y-m-d h:i:s',$time - $suspendseconds));
                            //Terminate conditions
                            //var_dump('Terminate: '.date('Y-m-d h:i:s',$time-$suspendseconds-$terminateseconds));
                            
                            
$is_terminate false;                            
                            
//Terminate is a bad thing we would do nothing
                            
                            /*                        
                            if(($time-$suspendseconds-$terminateseconds) > intval($my_invoice['due']) ){
                                echo 'Terminate <br />';
                                $server->terminate($user_pack['id']);
                                $is_terminate = true;
                            } */                            
                            //Proceed to suspend                             
                            
if ($is_terminate == false ) {
                                if((
$time $suspendseconds) > intval($my_invoice['due'])) {
                                    
//echo 'Suspend <br />';
                                    
$server->suspend($user_pack['id']);
                                }
                            }                    
                        }
                    } else {
                        
//If I'm in time                     
                        
if($time strtotime($my_invoice['created']) + $number_months_in_seconds) {
                            
//Creates an invoice
                            
$my_new_invoice $invoice->getInvoiceInfo($my_invoice['id']);
                            
//    var_dump($my_new_invoice);                            
                            //echo 'Create invoice<br />';
                            
$this->create($uid$my_new_invoice['amount'], $time intval($db->config('suspensiondays')*24*60*60), $my_new_invoice['notes'], $my_new_invoice['addon_fee']);                        
                        }    
                    }
                } else { 
# User has no invoice yet
                    //What to do here?
                    //$this->create($uid, $amount, $time+$number_months_in_seconds, ""); # Create Invoice
                
}
            }
        }
    } 
Reply
#14
5) Code examples in the comments? Not a big fan since it wastes a lot of space. Maybe this could be better achieved in the Wiki?
Kevin Mark - TheHostingTool Lead Developer
Reply
#15
(06-29-2010, 09:21 PM)Kevin Wrote: 5) Code examples in the comments? Not a big fan since it wastes a lot of space. Maybe this could be better achieved in the Wiki?

Well I still working that is not the final version, this is a pre-alpha version Big Grin
Reply
#16
For a pre-alpha it looks pretty nice!
Kevin Mark - TheHostingTool Lead Developer
Reply
#17
this is one of those plugins I am badly waiting for.
Reply
#18
this is what i need! when o were can i download this extension? it's gonna be free or paid? thanks
Reply
#19
hows work going on this plugin?
Reply
#20
(07-30-2010, 03:16 AM)darubillah Wrote: hows work going on this plugin?

You can check it by yourself on Google Code: http://code.google.com/p/bnpanel/

Julio is doing its best to have something working this week.
Any help is welcome (including to reinject the changes to THT), BTW.
Reply


Forum Jump:


Users browsing this thread: 6 Guest(s)