/** * Get an array of totals for the services selected by the user. */ private function getInvoiceTotals($customer, $commande) { // Determine the rental city $city = Goodcity::model()->findByPk($commande->comgoodcitykey); // Determine mailing city category $rental_period = $commande->comperiod; $cat = strtolower(trim($city->goodcategory)); $cat_lookup = 'cat_' . $cat . '_' . $rental_period; // Get rental rate $tarif = Tarif::model()->findByPk(1); $onetime = false; if (isset(Yii::app()->user->onetime)) { $onetime = true; $commande->comfrequency = Commande::TYPE_FREQUENCY_TYPE_8; } else { $onetime = false; } if ($onetime == true) { $rental_rate = 50; } else { $rental_rate = $tarif->{$cat_lookup}; } // Add in the setup charge - SETUP FEE WAIVED AS PER CLIENT'S REQUEST // $sub_total = $rental_rate + $tarif->reg_setup_us; $sub_total = $rental_rate; $total = $rental_rate; $administrative_cost = $total * 0.05; // Determine Canadian taxes // TODO: Why isn't the TVH tax used? if ($customer->bilcountry == "Canada") { switch ($customer->bilstate) { // NOTE: For reference, I've included the old tax calculation perl code // Filename: orderthree.cgi // // if ($a_state =~ /QC/) { // $tps_tax = ($sub_total * $taxtps); // $sub_tax = ($sub_total + $tps_tax); // $tvq_tax = ($sub_tax * $taxtvq); // $total = ($tps_tax + $tvq_tax + $sub_total); // } // // elsif ($a_state =~ /(AB''BC''MB''NB''NF''NT''NS''ON''PE''SK''YT)/) { // $tps_tax = ($sub_total * $taxtps); // $total = ($tps_tax + $sub_total); // $include_tps = 1; // } // // elsif ($a_state !~ /(AB''BC''MB''NB''NF''NT''NS''ON''PE''SK''YT''QC )/) { // $total = $sub_total; // } case 'QC': // GST: General tax for all of Canada $tps_tax = $sub_total * $tarif->taxtps; // PST: Is the provincial tax for Quebec... $sub_tax = $sub_total + $tps_tax; // ...it is added on top of the GST $tvq_tax = $sub_tax * $tarif->taxtvq; $total = $tps_tax + $tvq_tax + $sub_total; break; case 'AB': case 'BC': case 'MB': case 'NB': case 'NF': case 'NT': case 'NS': case 'ON': case 'PE': case 'SK': case 'YT': // GST: General tax for all of Canada $tps_tax = $sub_total * $tarif->taxtps; $tvq_tax = 0; $total = $tps_tax + $sub_total; break; default: // TODO: Don't take matters so lightly die; } } else { $tps_tax = 0; $tvq_tax = 0; } $deposit = null; // Determine mail forwarding deposit switch ($commande->comfrequency) { case Commande::TYPE_FREQUENCY_TYPE_1: $deposit = $tarif->reg_depositexp_now; break; case Commande::TYPE_FREQUENCY_TYPE_2: $deposit = $tarif->reg_depositexp_week; break; case Commande::TYPE_FREQUENCY_TYPE_3: $deposit = $tarif->reg_depositexp_bimonth; break; case Commande::TYPE_FREQUENCY_TYPE_4: $deposit = $tarif->reg_depositexp_month; break; case Commande::TYPE_FREQUENCY_TYPE_5: $deposit = $tarif->reg_depositair_week; break; case Commande::TYPE_FREQUENCY_TYPE_6: $deposit = $tarif->reg_depositair_month; break; case Commande::TYPE_FREQUENCY_TYPE_7: $deposit = $tarif->reg_depositair_bimonth; break; case Commande::TYPE_FREQUENCY_TYPE_8: $deposit = 0; break; default: // TODO: Replace this with an email to the system administrator die; } $total = $total + $deposit; $total = $total + $administrative_cost; // Format numbers before sending them back setlocale(LC_MONETARY, 'en_US'); $rental_rate = number_format($rental_rate, 2, '.', ','); $deposit = number_format($deposit, 2, '.', ','); $tps_tax = number_format($tps_tax, 2, '.', ','); $tvq_tax = number_format($tvq_tax, 2, '.', ','); $administrative_cost = number_format($administrative_cost, 2, '.', ','); $total = number_format($total, 2, '.', ','); return array('rental_rate' => $rental_rate, 'deposit' => $deposit, 'tax_gst' => $tps_tax, 'tax_pst' => $tvq_tax, 'administrative_cost' => $administrative_cost, 'total' => $total); }
/** * Returns the data model based on the primary key given in the GET variable. * If the data model is not found, an HTTP exception will be raised. * @param integer the ID of the model to be loaded */ public function loadModel($id) { $model = Tarif::model()->findByPk((int) $id); if ($model === null) { throw new CHttpException(404, 'The requested page does not exist.'); } return $model; }