public function saveAction() { $request = $this->getRequest(); if ($this->getRequest()->isPost()) { $model = new Kutu_Core_Orm_Table_Order(); /* update*/ //$row= $model->fetch("id=5")->current(); // tanpa current return rowset $row = $model->find("5")->current(); //primary key only findRow return row $row->name = 'ab'; $row->save(); /* insert */ $row = $model->fetchNew(); //balikin row empty, lihat di documentation $row->nama = ""; $row->field = $value; $row->save(); //return $this->_helper->redirector('index'); } $this->view->form = $form; }
function completeAction() { $formater = new Kutu_Core_Hol_User(); $defaultCurrency = 'Rp'; $kopel = $this->_request->getParam('kopel'); $method = $this->_request->getParam('method'); $packageId = $this->_request->getParam('packageId'); $paymentSubscription = $this->_request->getParam('payment'); $tblPaymentSetting = new Kutu_Core_Orm_Table_PaymentSetting(); $usdIdrEx = $tblPaymentSetting->fetchRow(" settingKey= 'USDIDR'"); $currencyValue = $usdIdrEx->settingValue; $rowTaxRate = $tblPaymentSetting->fetchRow("settingKey='taxRate'"); $taxRate = $rowTaxRate->settingValue; $tblUser = new Kutu_Core_Orm_Table_User(); $rowUser = $tblUser->find($kopel)->current(); /* $modelGroup = new Kutu_Core_Orm_Table_Group(); $row = $modelGroup->fetchRow("id=".$this->_user->packageId); if ($row->name == "free") { $rowUser->periodeId = 2; $rowUser->save(); } */ $this->view->rowUser = $rowUser; // discount $disc = $formater->checkPromoValidation('Disc', $packageId, $rowUser->promotionId, $paymentSubscription); $total = $formater->checkPromoValidation('Total', $packageId, $rowUser->promotionId, $paymentSubscription); $tblPackage = new Kutu_Core_Orm_Table_Package(); $rowPackage = $tblPackage->fetchRow("packageId={$packageId}"); $this->view->rowPackage = $rowPackage; $tblOrder = new Kutu_Core_Orm_Table_Order(); $row = $tblOrder->fetchNew(); $row->userId = $kopel; if ($this->getRequest()->getPost()) { $value = $this->getRequest()->getPost(); $row->taxNumber = $value['taxNumber']; $row->taxCompany = $value['taxCompany']; $row->taxAddress = $value['taxAddress']; $row->taxCity = $value['taxCity']; $row->taxZip = $value['taxZip']; $row->taxProvince = $value['taxProvince']; $row->taxCountryId = $value['taxCountry']; $row->paymentMethod = $method; } $row->datePurchased = date('YmdHis'); $row->paymentMethodNote = "membership"; if ($method == "nsiapay") { $row->orderStatus = 8; } else { $row->orderStatus = 1; //pending } $row->currency = $defaultCurrency; $row->currencyValue = $currencyValue; $row->orderTotal = $total; $row->ipAddress = Kutu_Lib_Formater::getRealIpAddr(); $orderId = $row->save(); $rowJustInserted = $tblOrder->find($orderId)->current(); $rowJustInserted->invoiceNumber = date('Ymd') . '.' . $orderId; $temptime = time(); $temptime = Kutu_Lib_Formater::DateAdd('d', 5, $temptime); $rowJustInserted->discount = $disc; $rowJustInserted->invoiceExpirationDate = strftime('%Y-%m-%d', $temptime); $rowJustInserted->save(); $this->view->invoiceNumber = $rowJustInserted->invoiceNumber; $this->view->datePurchased = $rowJustInserted->datePurchased; $tblOrderDetail = new Kutu_Core_Orm_Table_OrderDetail(); $rowDetail = $tblOrderDetail->fetchNew(); $rowDetail->orderId = $orderId; $rowDetail->itemId = $rowPackage->packageId; $modelGroup = new Kutu_Core_Orm_Table_Group(); $row = $modelGroup->fetchRow("id={$packageId}"); $group = "Subsciption for Member " . ucwords(strtolower($row->name)) . " " . $paymentSubscription . " Months"; $this->view->packageId = $packageId; $this->view->paymentSubscription = $paymentSubscription; $this->view->itemName = $group; $rowDetail->documentName = $group; $rowDetail->price = $total; $numOfUsers = $tblUser->getUserCount($rowUser->kopel); $this->view->numOfUsers = $numOfUsers; $this->view->grandtotal = $total; $this->view->method = $method; $this->view->orderId = $orderId; $this->view->total = $rowPackage->charge; $rowDetail->qty = $numOfUsers; $rowDetail->finalPrice = $total; $rowDetail->save(); $data = $this->_request->getParams(); $this->view->data = $data; $modDir = $this->getFrontController()->getModuleDirectory(); require_once $modDir . '/models/Store/Mailer.php'; $mod = new Membership_Model_Store_Mailer(); switch (strtolower($method)) { case 'manual': case 'bank': $mod->sendBankInvoiceToUser($orderId); break; case 'nsiapay': $mod->sendInvoiceToUser($orderId); break; } }
private function saveOrder($cart, $method) { $tblOrder = new Kutu_Core_Orm_Table_Order(); $row = $tblOrder->fetchNew(); $row->invoiceNumber = ''; //empty invoice for first initialisation $row->userId = $this->_userInfo->userId; //get value from post var (store/checkout.phtml) if ($this->getRequest()->getPost()) { $value = $this->getRequest()->getPost(); // get posted value $row->taxNumber = $value['taxNumber']; $row->taxCompany = $value['taxCompany']; $row->taxAddress = $value['taxAddress']; $row->taxCity = $value['taxCity']; $row->taxZip = $value['taxZip']; $row->taxProvince = $value['taxProvince']; $row->taxCountryId = $value['taxCountry']; $row->paymentMethod = $method; } $row->datePurchased = date('YmdHis'); $row->orderStatus = 1; //pending $row->currency = $this->_defaultCurrency; $row->currencyValue = $this->_currencyValue; $row->orderTotal = $cart['grandTotal']; $row->orderTax = $cart['taxAmount']; $row->ipAddress = $this->getRealIpAddress(); /*echo '<pre>'; //print_r($row); echo '</pre>';*/ $row->save(); $orderId = $tblOrder->getLastInsertId(); $_SESSION['_orderIdNumber'] = $orderId; $this->_orderIdNumber = $orderId; $tblOrderDetail = new Kutu_Core_Orm_Table_OrderDetail(); for ($iCart = 0; $iCart < count($cart['items']); $iCart++) { $rowDetail = $tblOrderDetail->fetchNew(); $itemId = $cart['items'][$iCart]['itemId']; $rowDetail->orderId = $orderId; $rowDetail->itemId = $itemId; $rowDetail->documentName = $cart['items'][$iCart]['item_name']; $rowDetail->price = $cart['items'][$iCart]['itemPrice']; $itemPrice = $rowDetail->price; @($rowDetail->tax = ($cart['grandTotal'] - $cart['subTotal']) / $cart['subTotal'] * 100); $rowDetail->qty = $cart['items'][$iCart]['qty']; $rowDetail->finalPrice = $itemPrice + $itemPrice * $this->_paymentVars['taxRate'] / 100; $rowDetail->save(); } return $orderId; }
private function saveOrder($cart, $method) { //[TODO] this value should be put into table KutuPaymentSetting $defaultCurrency = 'USD'; $tblPaymentSetting = new Kutu_Core_Orm_Table_PaymentSetting(); $usdIdrEx = $tblPaymentSetting->fetchRow(" settingKey= 'USDIDR'"); $currencyValue = $usdIdrEx->settingValue; $rowTaxRate = $tblPaymentSetting->fetchRow("settingKey='taxRate'"); $taxRate = $rowTaxRate->settingValue; //die($currencyValue); $auth = Zend_Auth::getInstance(); $userId = $auth->getIdentity()->guid; $tblOrder = new Kutu_Core_Orm_Table_Order(); $row = $tblOrder->fetchNew(); $row->userId = $userId; //get value from post var (store/checkout.phtml) if ($this->getRequest()->getPost()) { $value = $this->getRequest()->getPost(); // get posted value $row->taxNumber = $value['taxNumber']; $row->taxCompany = $value['taxCompany']; $row->taxAddress = $value['taxAddress']; $row->taxCity = $value['taxCity']; $row->taxZip = $value['taxZip']; $row->taxProvince = $value['taxProvince']; $row->taxCountryId = $value['taxCountry']; $row->paymentMethod = $method; } $row->datePurchased = date('YmdHis'); $row->orderStatus = 1; //pending $row->currency = $defaultCurrency; $row->currencyValue = $currencyValue; $row->orderTotal = $cart['grandTotal']; $row->orderTax = $cart['taxAmount']; $row->ipAddress = $this->getRealIpAddress(); /*echo '<pre>'; //print_r($row); echo '</pre>';*/ $orderId = $row->save(); //$orderId = $tblOrder->getLastInsertId(); $rowJustInserted = $tblOrder->find($orderId)->current(); $rowJustInserted->invoiceNumber = date('Ymd') . '.' . $orderId; $rowJustInserted->save(); $this->view->invoiceNumber = $rowJustInserted->invoiceNumber; $tblOrderDetail = new Kutu_Core_Orm_Table_OrderDetail(); for ($iCart = 0; $iCart < count($cart['items']); $iCart++) { $rowDetail = $tblOrderDetail->fetchNew(); $itemId = $cart['items'][$iCart]['itemId']; $rowDetail->orderId = $orderId; $rowDetail->itemId = $itemId; $rowDetail->documentName = $cart['items'][$iCart]['item_name']; $rowDetail->price = $cart['items'][$iCart]['itemPrice']; $itemPrice = $rowDetail->price; @($rowDetail->tax = ($cart['grandTotal'] - $cart['subTotal']) / $cart['subTotal'] * 100); $rowDetail->qty = $cart['items'][$iCart]['qty']; $rowDetail->finalPrice = $itemPrice + $itemPrice * $taxRate / 100; $rowDetail->save(); } //[TODO] MUST ALSO INSERT/UPDATE KutuUserFinance return $orderId; }