/** * Displays the currently logged in user's account information */ public function actionInfo() { // Get id of logged in user $user_id = Yii::app()->user->getId(); $customer = Customer::model()->findByPk($user_id); $commande = Commande::model()->findAllByAttributes(array('bilkey' => $user_id)); $service_details = Customer::model()->getCustomerServiceDetails($user_id); $shipment_details = Customer::model()->getShipmentsByCustomerBilkey($user_id); if (isset($_POST['Customer'])) { $customer->setScenario('user_edit'); // Populate our new models from the input arrays $customer->attributes = $_POST['Customer']; // If a model saves, we know it's valid if ($customer->validate()) { // Send email to info@mailnetwork and client $customer->save(); $this->actionEmailChanges('customer', $customer, $customer); } } $shipment_model = new Shipment('search'); $shipment_model->unsetAttributes(); // clear any default values $shipment_model->bilkey = $user_id; if (isset($_GET['Shipment'])) { $shipment_model->attributes = $_GET['Shipment']; } $this->render('//shared/user-info', array('customer_model' => $customer, 'customer' => $customer, 'commande' => $commande, 'service_details' => $service_details, 'shipment_details' => $shipment_details, 'shipment_model' => $shipment_model)); }
/** * for Customer Service View */ public function actionCustomerService() { $this->layout = '//layouts/column1'; $model = new Shipment('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['Shipment'])) { $model->attributes = $_GET['Shipment']; } $this->render('admin', array('model' => $model)); }
/** * Updates a particular model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id the ID of the model to be updated */ public function actionUpdate($id) { $model = $this->loadModel($id); // Uncomment the following line if AJAX validation is needed // $this->performAjaxValidation($model); if (isset($_POST['Customer'])) { $model->attributes = $_POST['Customer']; $model->save(); $this->redirect("#info"); // $this->redirect(array('view','id'=>$model->bilkey)); } if (isset($_GET['Shipment'])) { $shipment_model->attributes = $_GET['Shipment']; } $service_details = Customer::model()->getCustomerServiceDetails($id); $shipment_details = Customer::model()->getShipmentsByCustomerBilkey($id); $customer = Customer::model()->findByPk($id); $commande = Commande::model()->findAllByAttributes(array('bilkey' => $id)); $shipment_model = new Shipment('search'); $shipment_model->unsetAttributes(); // clear any default values $shipment_model->bilkey = $id; // DEBUGGING // print "New total: " + $total_balance . '<br />'; // print "Old total: " + $customer->bilbalance; // die; // TODO: We really should link the billing activity with the comkey... if (isset($_POST['Shipment'])) { // Check if it's an update if (isset($_POST['update'])) { $shipment = Shipment::model()->findByPk($_POST['update']); $shipment->attributes = $_POST['Shipment']; // We have to cast these manually. For some reason this fails on the production server... $shipment->shipdebit = floatval($shipment->shipdebit); $shipment->shipcredit = floatval($shipment->shipcredit); // If the user leaves these fields blank, let's assume // they meant to input a 0. if (empty($shipment->shipdebit) || $shipment->shipdebit == null) { $shipment->shipdebit = 0; } if (empty($shipment->shipcredit) || $shipment->shipcredit == null) { $shipment->shipcredit = 0; } // TODO: We should prolly check this $shipment->save(); } else { $shipment = new Shipment(); $shipment->attributes = $_POST['Shipment']; // We have to cast these manually. For some reason this fails on the production server... $shipment->shipdebit = floatval($shipment->shipdebit); $shipment->shipcredit = floatval($shipment->shipcredit); // If the user leaves these fields blank, let's assume // they meant to input a 0. if (empty($shipment->shipdebit) || $shipment->shipdebit == null) { $shipment->shipdebit = 0; } if (empty($shipment->shipcredit) || $shipment->shipcredit == null) { $shipment->shipcredit = 0; } if ($shipment->validate()) { $shipment->comkey = $commande[0]->comkey; $shipment->bilkey = $customer->bilkey; $shipment->save(); } } // $this->redirect("customer/update/id/" + $customer->bilkey); $this->redirect("#billing"); } $conn = Yii::app()->db; // $total_balance = 0; // Update individual account balances foreach ($commande as $c) { $command = $conn->createCommand("SELECT SUM(shipcredit) - SUM(shipdebit) as balance FROM shipment WHERE comkey='" . $c->comkey . "' GROUP BY comkey"); $results = $command->queryRow(); $balance = $results['balance']; // $total_balance += $balance; $c->dest_bilbalance = $balance; $c->save(); } // Fix for Support Request #430 $command = $conn->createCommand("SELECT SUM(shipcredit) - SUM(shipdebit) as balance FROM shipment WHERE bilkey='" . $customer->bilkey . "'"); $results = $command->queryRow(); $total_balance = $results['balance']; // Update overall account balance $customer->bilbalance = $total_balance; $customer->save(); $this->render('//shared/user-info', array('admin' => 1, 'commande' => $commande, 'customer' => $customer, 'customer_model' => $customer, 'service_details' => $service_details, 'shipment_details' => $shipment_details, 'shipment_model' => $shipment_model)); }
/** * Manages all models. */ public function actionAdmin() { $model = new Shipment('search'); $model->unsetAttributes(); // clear any default values if (isset($_GET['Shipment'])) { $model->attributes = $_GET['Shipment']; } $this->render('admin', array('model' => $model)); }