コード例 #1
0
    public static function checkDate($date,$client_id){

        $dcss = self::model()->findByPk($client_id);
        if ($dcss) {
            if (strtotime($date) >= strtotime($dcss->Active_From)) {
                $currentSettings = ClientServiceSettings::model()->findByPk($client_id);
                $currentSettings->Service_Level_ID = $dcss->Service_Level_ID;
                $currentSettings->Additional_Users = $dcss->Additional_Users;
                $currentSettings->Additional_Projects = $dcss->Additional_Projects;
                $currentSettings->Additional_Storage = $dcss->Additional_Storage;
                $currentSettings->Active_To = $dcss->Active_To;
                $currentSettings->Fee = $dcss->Fee;
                $currentSettings->save();

                $dcss->delete();
            }
        }

    }
コード例 #2
0
    /**
     * Recalculate Pending Settings (based on number of day )
     * @param $pcss
     * @param $active_to
     * @param $monthly_price
     */
    public static function recalculateSettings($pcss,$active_to,$monthly_price) {

        $css = ClientServiceSettings::model()->findByPk($pcss->Client_ID);
        //for pending settings
        $datetime1 = date_create(date('Y-m-d'));
        $datetime2 = date_create($active_to);
        $diff = date_diff($datetime1, $datetime2, true);
        $days_to_charge = $diff->days;

        //for previous settings
        $datetime_prev1 = date_create($css->Active_To);
        $datetime_prev2 = date_create($active_to);
        $diff = date_diff($datetime_prev1, $datetime_prev2, true);
        $days_to_charge_prev = $diff->days;





        $added_price = ($monthly_price - $css->Fee);
        $added_price_til_the_end = floatval($added_price /30 * $days_to_charge);

        $base_price_till_the_end = floatval($css->Fee /30 * $days_to_charge_prev);

        $total_price_till_the_end = $added_price_til_the_end + $base_price_till_the_end;




        $pcss->Fee = round($monthly_price,2);
        $pcss->Fee_To_Upgrade = round($total_price_till_the_end,2);
        $pcss->save();

        }
コード例 #3
0
    /**
     * Returns array of summarized settings for current client
     * @return array Tier_Name,Users_Count, Projects_Count, Storage_Count, Base_Fee, Additional_Users,Additional_Projects,Additional_Storage,Additional_Fee
     */
    public static function getSummarySettings($client_id) {
        $result = array();
        $i= 0;
        $limiter ='';
        $client_id = $client_id ? $client_id :Yii::app()->user->clientID;

        $css = ClientServiceSettings::model()->findByPk($client_id);
        $result['Tiers_Str'] = $css->Service_Level_ID;
        $tiers_array = explode(',',$result['Tiers_Str']);
        foreach ($tiers_array as $id) {
            $settings = ServiceLevelSettings::model()->findByPk($id);

            if ($i != 0) {$limiter = ', ';}
            if ($settings->Service_Level_ID == 1) {
                $w9_exist =true;
                $w9_price = $settings->Base_Fee;
                $result['levels_checksum']+=1;
            }
            if ($settings->Service_Level_ID == 2) {
                $result['levels_checksum']+=5;
            }
            if ($settings->Service_Level_ID == 3) {
                $result['levels_checksum']+=10;
            }if ($settings->Service_Level_ID == 4) {
                $result['levels_checksum']+=20;
            }

            $result['Tier_Name'] .= $limiter.$settings->Tier_Name;
            $i++;
         }

        $add_users_price = $settings->Additional_User_Fee;
        $add_projects_price = $settings->Additional_Project_Fee;
        $add_storage_price = $settings->Additional_Storage_Fee;

        $result['Base_Fee'] =  ClientServiceSettings::CalculateBaseFee($tiers_array);
        $result['Users_Count'] = $settings->Users_Count;
        $result['Projects_Count'] = $settings->Projects_Count;
        $result['Storage_Count'] = $settings->Storage_Count;

            $result['Additional_Users'] =$css->Additional_Users;
            $result['Additional_Projects'] =$css->Additional_Projects;
            $result['Additional_Storage'] =$css->Additional_Storage;
            $result['Storage_Index'] = ServiceLevelSettings::getStorageIndexByValue($css->Additional_Storage);
            $result['Additional_Fee'] = $add_users_price * $css->Additional_Users + $add_projects_price*($css->Additional_Projects) + $add_storage_price* ($result['Storage_Index']);

            //$result['Additional_Storage'] =$settings->	Additional_Storage;

        $users = UsersClientList::model()->findAllByAttributes(array(
            'Client_ID'=>$client_id
        ));
        $result['Used_Users'] =count($users);

        $result['Used_Projects'] = Projects::clientProjectUsage();
        $result['Used_Storage'] = ceil(Images::getUsedStorage($client_id));


        return $result;
    }
コード例 #4
0
    /**
     * Update company service level and add payment
     */
    public function actionUpdateCompanyServiceLevel()
    {
        if (isset($_POST['ClientServiceSettings']) && is_array($_POST['ClientServiceSettings'])
            && isset($_POST['Tiers']) && is_array($_POST['Tiers'])
        ) {
            $client_id = intval($_POST['ClientServiceSettings']['Client_ID']);
            $css = ClientServiceSettings::model()->findByPk($client_id);

            $pcss = PendingClientServiceSettings::model()->findByPk($client_id);
            if ($pcss) {$pending_fee = $pcss->Fee;}

            $client = $css->client;
        //1) add payment
            $amount = floatval($_POST['add_payment_amount']);
            $date = trim($_POST['add_payment_date']);
            $number = trim($_POST['add_payment_number']);
            $date = Helper::checkDate($date);

            $users = intval($_POST['ClientServiceSettings']['Additional_Users']);
            $projects = intval($_POST['ClientServiceSettings']['Additional_Projects']);
            $storage = intval($_POST['ClientServiceSettings']['Additional_Storage']);

            $min_max_is_valid = ClientServiceSettings::CheckMinMaxValues($users,$projects,$storage);

            if ($min_max_is_valid) {
                if ($client && $amount > 0 && preg_match('/^\d{4}\-\d{2}\-\d{2}$/', $date)) {
                    $result = ServicePayments::addJustPayment($client_id, $amount, $date,$number,'');
                }
            }



        //2) update settings

            if ($css && $client && $min_max_is_valid) {
                $_POST['ClientServiceSettings']['Active_To'] = Helper::checkDate($_POST['ClientServiceSettings']['Active_To']);

                $css->setAttributes($_POST['ClientServiceSettings']);
                //$css->Additional_Storage--;
                //$companyServiceSettings->Service_Level_ID = implode(',',$_POST['Tiers']);

                //$fee = ClientServiceSettings::Calculation($css->Additional_Users,$css->Additional_Projects,$css->Additional_Storage,$css->Active_To,$css->Service_Level_ID,$client_id);

                //new settings and prices
                $base_fee_new = ClientServiceSettings::CalculateBaseFee(explode(',',$css->Service_Level_ID));

                $add_fee_new = ClientServiceSettings::CalculateAddFee($css->Additional_Users,$css->Additional_Projects,$css->Additional_Storage);

                $fee = $base_fee_new + $add_fee_new;
                $css->Additional_Storage--;
                /**$fee = $amount ? $amount :
                    ClientServiceSettings::getFeeByValues(
                        $companyServiceSettings->Service_Level_ID,
                        $companyServiceSettings->Additional_Users,
                        $companyServiceSettings->Additional_Projects,
                        $companyServiceSettings->Additional_Storage
                    );
                 */

                //$periods = Helper::calculatePeriodsBetweenDates(date('m/d/Y'),$companyServiceSettings->Active_To);

                $css->Fee = $fee; //* $periods;

                if ($css->validate()) {
                    $css->save();
                    if ($pcss) $pcss->delete();
                    if ($css->Active_To >= date('Y-m-d') && $client->Client_Status == Clients::NOT_ACTIVE) {
                        $client->activate();
                    }

                    $user_client_settings = $client->service_settings;
                    $user_tier_settings = TiersSettings::agregateTiersSettings($user_client_settings->Service_Level_ID);
                    Yii::app()->user->setState('tier_settings', $user_tier_settings);
                }
            }

        Yii::app()->user->setFlash('success', "Settings added");
        $this->redirect('/admin?tab=service');
    }
    }
コード例 #5
0
    public static function AddThreeDays($client_id) {

        $css = ClientServiceSettings::model()->findByPk($client_id);
    //    $pcss = PendingClientServiceSettings::model()->findByPk($css->Client_ID);

        $current_date_exp = $css->Active_To;
        $three_days_add = date('Y-m-d',strtotime("+3 day", strtotime($current_date_exp)));



    //    $css->Service_Level_ID = $pcss->Service_Level_ID;
    //    $css->Additional_Users = $pcss->Additional_Users - $summary_settings['Users_Count'];
    //    $css->Additional_Projects = $pcss->Additional_Projects - $summary_settings['Projects_Count'];
    //    $css->Additional_Storage = $pcss->Additional_Storage - $summary_settings['Storage_Count'];
    //    $css->Active_To = $pcss->Pending_Active_To;
          $css->Active_To = $three_days_add;

    //    $css->Fee = $pcss->Fee;

          $css->Locked = date('Y-m-d'); //means that clients settings were locked on this day, and from this date we will count trial period
          $css->save();

    //    $pcss->delete();

    }
コード例 #6
0
ファイル: ServicePayments.php プロジェクト: ranvijayj/htmlasa
    /**
     * Generate invoice
     * @param $clientID
     * @param $amount
     */
    public static function generateInvoice($clientID, $userID, $amount)
    {

       $client = Clients::model()->with('company.adreses')->findByPk($clientID);

       $user = Users::model()->with('person')->findByPk($userID);


        $settingsToPay= PendingClientServiceSettings::model()->findByAttributes(array(
            'Client_ID'=>$clientID,
            'Approved'=>1
            )
        );


        if($settingsToPay) {
            //$str = ServiceLevelSettings::getSummaryName($settingsToPay->Service_Level_ID);

            $sum_settings = ServiceLevelSettings::getSummarySettings($clientID);
            $tierName=$sum_settings['Tier_Name'];

            $data['service']['total_users'] = $settingsToPay->Additional_Users ;
            $data['service']['total_projects'] = $settingsToPay->Additional_Projects ;
            $data['service']['total_storage'] = $settingsToPay->Additional_Storage ;

            $data['service']['added_users'] = $settingsToPay->Additional_Users - $sum_settings['Users_Count'];
            $data['service']['added_projects'] = $settingsToPay->Additional_Projects ;
            $data['service']['added_storage'] = $settingsToPay->Additional_Storage ;

            $active_to = $settingsToPay->Pending_Active_To;
        }
        else {
            $settingsToPay= ClientServiceSettings::model()->findByPk($clientID);
            $sum_settings = ServiceLevelSettings::getSummarySettings($clientID);
            $tierName=$sum_settings['Tier_Name'];

            $data['service']['total_users'] = $settingsToPay->Additional_Users + $sum_settings['Users_Count'];
            $data['service']['total_projects'] = $settingsToPay->Additional_Projects + $sum_settings['Projects_Count'];
            $data['service']['total_storage'] = $settingsToPay->Additional_Storage + $sum_settings['Storage_Count'];

            $data['service']['added_users'] = $settingsToPay->Additional_Users;
            $data['service']['added_projects'] = $settingsToPay->Additional_Projects;
            $data['service']['added_storage'] = $settingsToPay->Additional_Storage;

            $active_to = $settingsToPay->Active_To;

        }

        $summary_sl_settings = ServiceLevelSettings::getSummarySettings($clientID);

        $data['company_to']['company_name']=$client->company->Company_Name;
        $data['company_to']['street']=$client->company->adreses[0]->Address1;
        $data['company_to']['city']=$client->company->adreses[0]->City."  ".$client->company->adreses[0]->ZIP;;
        $data['company_to']['country']=$client->company->adreses[0]->Country;
        $data['company_to']['email']=$user->person->Email;
        $data['company_to']['phone']=$user->person->Mobile_Phone;

        $data['invoice']['number']=Aps::generateInvoiceNumber($clientID);
        $data['invoice']['date']=date("M d, Y",time());
        $data['invoice']['due_date']=date("M d, Y",time());
        $data['invoice']['due_date']=date("M d, Y",time());
        $data['invoice']['amount_due']=$amount;

        $data['service']['service_name']=$tierName;


        /*$data['service']['Users']=$summary_sl_settings['Additional_Users']+$summary_sl_settings['Users_Count'];
        $data['service']['Projects']=$summary_sl_settings['Additional_Projects']+$summary_sl_settings['Projects_Count'];
        $data['service']['Storage']=$summary_sl_settings['Additional_Storage']+$summary_sl_settings['Storage_Count'];*/
        $data['service']['active_to'] = $active_to;




        // get content for pdf
        $content = Yii::app()->controller->renderPartial('application.views.myaccount.invoice_template', array(
            'data'=>$data,
        ), true);

        $fileName = date("Y_m_d_H_i_s") . '.pdf';
        Yii::import('ext.html2pdf.HTML2PDF');
        $html2pdf = new HTML2PDF('P', 'A4', 'en');
        $html2pdf->writeHTML($content);
        $html2pdf->Output($fileName, 'I');
        die;
    }