/** * Finds the Customer model based on its primary key value. * If the model is not found, a 404 HTTP exception will be thrown. * @param integer $id * @return Customer the loaded model * @throws NotFoundHttpException if the model cannot be found */ protected function findModel($id) { if (($model = Customer::findOne($id)) !== null) { return $model; } else { throw new NotFoundHttpException('The requested page does not exist.'); } }
public function actionIndexWithRelationships() { $room_id = Yii::$app->request->get('room_id', null); $reservation_id = Yii::$app->request->get('reservation_id', null); $customer_id = Yii::$app->request->get('customer_id', null); $roomSelected = null; $reservationSelected = null; $customerSelected = null; if ($room_id != null) { $roomSelected = Room::findOne($room_id); $rooms = array($roomSelected); $reservations = $roomSelected->reservations; $customers = $roomSelected->customers; } elseif ($reservation_id != null) { $reservationSelected = Reservation::findOne($reservation_id); $rooms = array($reservationSelected->room); $reservations = array($reservationSelected); $customers = array($reservationSelected->customer); } elseif ($customer_id != null) { $customerSelected = Customer::findOne($customer_id); $rooms = $customerSelected->rooms; $reservations = $customerSelected->reservations; $customers = array($customerSelected); } else { $rooms = Room::find()->all(); $reservations = Reservation::find()->all(); $customers = Customer::find()->all(); } return $this->render('indexWithRelationShips', compact('roomSelected', 'reservationSelected', 'customerSelected', 'rooms', 'reservations', 'customers')); }
public function actionGetCustomerDetail($customerID) { $customer = Customer::findOne($customerID); echo Json::encode($customer); }
/** * Updates an existing PurchaseOrder model. * If update is successful, the browser will be redirected to the 'view' page. * @param integer $id * @return mixed */ public function actionUpdate($id) { $model = $this->findModel($id); $updatePODetail = new PurchaseOrderDetail(); $poDetails = PurchaseOrderDetail::find()->where(['purchaseorderdetail_purchaseorderid' => $id])->orderBy('purchaseorderdetail_id')->all(); $product = Product::find()->where(['product_type' => 'p'])->orderBy('product_id')->all(); $service = Product::find()->where(['product_type' => 's'])->orderBy('product_id')->all(); $customer = Customer::find()->orderBy('customer_name')->all(); $company = Company::findOne(1); $customerID = $model->purchaseorder_customerid; $thisCustomer = Customer::findOne($customerID); $uid = Yii::$app->user->identity->user_id; $uname = Yii::$app->user->identity->user_name; if (isset($_POST['description'])) { $poDetailList = $_POST['description']; $customer_id = $_POST['customer-list']; $po_id = $_POST['po_id']; $po_no = $_POST['po_no']; $po_date = $_POST['po_date']; $productType = $_POST['productType']; $qty = $_POST['qty']; $unit = $_POST['unit']; $cost = $_POST['cost']; $hidden_price = $_POST['hidden_price']; $hidden_gst = $_POST['hidden_gst']; $hidden_tax_code = $_POST['hidden_tax_code']; $hidden_tax_rate = $_POST['hidden_tax_rate']; $hidden_price_gst = $_POST['hidden_price_gst']; $hidden_total = $_POST['hidden_total']; $hidden_gsttotal = $_POST['hidden_gsttotal']; $hidden_gstpricetotal = $_POST['hidden_gstpricetotal']; $hidden_id = $_POST['hidden_id']; $hidden_poid = $_POST['hidden_poid']; $hidden_product_name = $_POST['hidden_product_name']; if ($updateQPODetail != NULL) { $updateQPODetail = $this->findModel($id); $updateQPODetail->purchaseorder_id = $po_id; $updateQPODetail->purchaseorder_no = $po_no; $updateQPODetail->purchaseorder_date = $po_date; $updateQPODetail->purchaseorder_date_transaction = $po_date; $updateQPODetail->purchaseorder_date_delete = $po_date; $updateQPODetail->purchaseorder_customerid = $customer_id; $updateQPODetail->purchaseorder_supplierid = 1; $updateQPODetail->purchaseorder_supplier_quotation_no = 11; $updateQPODetail->purchaseorder_createid = $uid; $updateQPODetail->purchaseorder_createname = $uname; $updateQPODetail->purchaseorder_remark = "lol"; $updateQPODetail->purchaseorder_system = "y"; $updateQPODetail->purchaseorder_partno = "y"; $updateQPODetail->purchaseorder_charge = 123; $updateQPODetail->purchaseorder_update_stock_status = "y"; $updateQPODetail->purchaseorder_status = "y"; $updateQPODetail->purchaseorder_tax_label = "lol"; $updateQPODetail->purchaseorder_tax_percent = 1; $updateQPODetail->purchaseorder_tax_amount = 100; $updateQPODetail->purchaseorder_printed_status = "y"; $updateQPODetail->purchaseorder_revision = 1; $updateQPODetail->purchaseorder_parts_total = $hidden_total; $updateQPODetail->purchaseorder_deleteid = 1; $updateQPODetail->purchaseorder_payment_status = "y"; $updateQPODetail->purchaseorder_no_user_format = "lol"; $updateQPODetail->purchaseorder_auto_generate = "y"; $updateQPODetail->purchaseorder_creditorid = 1; $updateQPODetail->purchaseorder_purchase_return = 123; $updateQPODetail->purchaseorder_payment_paid_thus_far = 123; $updateQPODetail->purchaseorder_outstanding_amount = 123; $updateQPODetail->purchaseorder_projectid = 1; $updateQPODetail->purchaseorder_gst_payable = $hidden_gsttotal; $updateQPODetail->purchaseorder_total_amount = $hidden_gstpricetotal; $updateQPODetail->save(); foreach ($poDetailList as $key => $n) { if ($hidden_poid[$key] != $id || $hidden_poid[$key] == NULL || $hidden_poid[$key] == '') { if ($unit[$key] == NULL) { $unit[$key] = "-"; } $newPODetail = new PurchaseOrderDetail(); $newPODetail->purchaseorderdetail_purchaseorderid = $po_id; $newPODetail->purchaseorderdetail_productid = $n; $newPODetail->purchaseorderdetail_partno = "lol"; $newPODetail->purchaseorderdetail_productname = $hidden_product_name[$key]; $newPODetail->purchaseorderdetail_unit = $qty[$key]; $newPODetail->purchaseorderdetail_unitname = $unit[$key]; $newPODetail->purchaseorderdetail_product_cost = $cost[$key]; $newPODetail->purchaseorderdetail_price = $hidden_price[$key]; $newPODetail->purchaseorderdetail_unitsent = 0; $newPODetail->purchaseorderdetail_status = "y"; $newPODetail->purchaseorderdetail_tax_code = $hidden_tax_code[$key]; $newPODetail->purchaseorderdetail_tax_rate = $hidden_tax_rate[$key]; $newPODetail->purchaseorderdetail_tax_amount = $hidden_gst[$key]; $newPODetail->purchaseorderdetail_total_amount = $hidden_price_gst[$key]; $newPODetail->purchaseorderdetail_gst_status = 1; $newPODetail->save(); } elseif ($hidden_poid[$key] == $id) { $poid = $hidden_id[$key]; $updatePODetail = PurchaseOrderDetail::findOne($poid); $updatePODetail->purchaseorderdetail_purchaseorderid = $po_id; $updatePODetail->purchaseorderdetail_productid = $n; $updatePODetail->purchaseorderdetail_partno = "lol"; $updatePODetail->purchaseorderdetail_productname = $hidden_product_name[$key]; $updatePODetail->purchaseorderdetail_unit = $qty[$key]; $updatePODetail->purchaseorderdetail_unitname = $unit[$key]; $updatePODetail->purchaseorderdetail_product_cost = $cost[$key]; $updatePODetail->purchaseorderdetail_price = $hidden_price[$key]; $updatePODetail->purchaseorderdetail_unitsent = 0; $updatePODetail->purchaseorderdetail_status = "y"; $updatePODetail->purchaseorderdetail_tax_code = $hidden_tax_code[$key]; $updatePODetail->purchaseorderdetail_tax_rate = $hidden_tax_rate[$key]; $updatePODetail->purchaseorderdetail_tax_amount = $hidden_gst[$key]; $updatePODetail->purchaseorderdetail_total_amount = $hidden_price_gst[$key]; $updatePODetail->purchaseorderdetail_gst_status = 1; $updatePODetail->save(); } } } } if ($updatePODetail->save()) { return $this->redirect(['index']); } elseif ($updatePODetail->load(Yii::$app->request->post())) { return $this->redirect(['index']); } else { return $this->render('update', ['model' => $model, 'poDetails' => $poDetails, 'product' => $product, 'service' => $service, 'customer' => $customer, 'thisCustomer' => $thisCustomer, 'company' => $company]); } }