function invoicelistAction() { if (!Pandamp_Controller_Action_Helper_IsAllowed::isAllowed('membership', 'all')) { $this->_redirect(ROOT_URL . '/' . $this->_zl->getLanguage() . '/error/restricted'); } $this->_helper->layout->setLayout('layout-customer-credential'); $id = $this->_getParam("id"); $userInvoiceList = App_Model_Show_Invoice::show()->getInvoiceById($id); $this->view->userInvoiceList = $userInvoiceList; $user = App_Model_Show_User::show()->getUserById($id); if ($user) { $this->view->user = $user; } $this->view->identity = $this->_user; /** * UPDATED:July 25, 2012 * @modifiedDate: 2012-11-20 15:10N * @todo Invoice can add more than one * comment line 897-899 */ if ($this->getRequest()->isPost()) { if (isset($user['paymentId']) && $user['paymentId'] != 0) { $tblInvoice = new App_Model_Db_Table_Invoice(); // $where = $tblInvoice->getAdapter()->quoteInto("uid=?",$this->getRequest()->getPost('kopel')); // $rowInvoice = $tblInvoice->fetchAll($where); // if (count($rowInvoice) <= 0) // { $rowInvoice = $tblInvoice->fetchNew(); $rowInvoice->uid = $this->getRequest()->getPost('kopel'); $rowInvoice->price = $this->getRequest()->getPost('price'); $rowInvoice->discount = $this->getRequest()->getPost('disc'); $rowInvoice->invoiceOutDate = $this->getRequest()->getPost('invoiceOutDate'); $rowInvoice->invoiceConfirmDate = $this->getRequest()->getPost('invoiceConfirmDate'); $rowInvoice->clientBankAccount = $this->getRequest()->getPost('clientBankAccount'); $rowInvoice->isPaid = $this->getRequest()->getPost('isPaid'); $rowInvoice->expirationDate = $this->getRequest()->getPost('expirationDate'); $rowInvoice->save(); } else { die('Lamanya berlangganan kosong, silahkan edit dulu data pelanggan'); } $this->_redirect(ROOT_URL . '/' . $this->_zl->getLanguage() . '/customer/user/invoicelist/id/' . $this->getRequest()->getPost('kopel')); // } } }
/** * _writeInvoice : Individual & Korporasi * @modifiedDate : 2012-11-20 12:53N * @todo Changed invoiceOutDate with createdDate from User Table * @return */ function _writeInvoice($memberId, $totalPromo, $discPromo, $payment, $access = '') { //$aclMan = Pandamp_Acl::manager(); $tblInvoice = new App_Model_Db_Table_Invoice(); $where = $tblInvoice->getAdapter()->quoteInto("uid=?", "{$memberId}"); $rowInvoice = $tblInvoice->fetchAll($where); if (count($rowInvoice) <= 0) { $tblUser = new App_Model_Db_Table_User(); $rowUser = $tblUser->fetchRow("kopel='" . $memberId . "'"); $rowInvoice = $tblInvoice->fetchNew(); $rowInvoice->uid = $memberId; $rowInvoice->price = $totalPromo; $rowInvoice->discount = $discPromo; //$rowInvoice->invoiceOutDate = date("Y-m-d"); $rowInvoice->invoiceOutDate = date("Y-m-d", strtotime($rowUser->createdDate)); $rowInvoice->invoiceConfirmDate = "0000-00-00"; //$temptime = time(); $temptime = strtotime($rowUser->createdDate); if ($rowUser->trialInDays == 0) { $trial = 5; } else { $trial = $rowUser->trialInDays; } $temptime = Pandamp_Lib_Formater::DateAdd('d', $trial, $temptime); $rowInvoice->expirationDate = strftime('%Y-%m-%d', $temptime); if (empty($access)) { $rowInvoice->save(); } else { $result = $rowInvoice->save(); if ($result) { $r = $memberId . " OK"; } else { $r = 'failure'; } } } else { if (!empty($access)) { $r = "invoice:{$memberId} sudah pernah dibuat!"; } } return $r; }
/** * @modifiedDate: 2012-11-20 15:25 * @todo Changed $temptime = strtotime($rowset->expirationDate) * */ function renewAction() { if (!Pandamp_Controller_Action_Helper_IsAllowed::isAllowed('membership', 'all')) { $this->_redirect(ROOT_URL . '/' . $this->_zl->getLanguage() . '/error/restricted'); } $this->_helper->layout->disableLayout(); $this->_helper->viewRenderer->setNoRender(TRUE); $aResult = array(); $id = $this->_request->getParam('id') ? $this->_request->getParam('id') : ''; $tblInvoice = new App_Model_Db_Table_Invoice(); $rowset = $tblInvoice->fetchRow("invoiceId=" . $id . " AND isPaid='Y'"); if ($rowset) { $rowInvoice = $tblInvoice->fetchNew(); $rowInvoice->uid = $rowset->uid; $rowUser = App_Model_Show_User::show()->getUserById($rowset->uid); if (isset($rowUser['paymentId']) && $rowUser['paymentId'] != 0) { $todays_date = date("Y-m-d"); $tblPackage = new App_Model_Db_Table_Package(); $rowPackage = $tblPackage->fetchRow("packageId=" . $rowUser['packageId'] . ""); if ($rowUser['paymentId'] == 12) { $price = $rowPackage->charge * 11; $price = $price + 0.1 * $price; } else { $price = $rowPackage->charge * $rowUser['paymentId']; $price = $price + 0.1 * $price; } //$rowInvoice->price = $rowset->price; $rowInvoice->price = $price; $rowInvoice->discount = $rowset->discount; $rowInvoice->invoiceOutDate = $rowset->expirationDate; $rowInvoice->invoiceConfirmDate = $todays_date; $rowInvoice->clientBankAccount = $rowset->clientBankAccount; $rowInvoice->isPaid = 'Y'; // get expiration date //$temptime = time(); $temptime = strtotime($rowset->expirationDate); //$temptime = strtotime($todays_date); // Expire dihitung setelah pelanggan membayarar $temptime = Pandamp_Lib_Formater::DateAdd('m', $rowUser['paymentId'], $temptime); $expiredDate = strftime('%Y-%m-%d', $temptime); $today = strtotime($todays_date); $expiration_date = strtotime($expiredDate); if ($expiration_date < $today) { $rowset->isPaid = 'E'; // status expire $rowset->save(); $notes = date("Y-m-d h:i:s") . " - Invoice expired:" . $id; $data = array('notes' => new Zend_Db_Expr("CONCAT(ifnull(notes,''),' \n{$notes}')")); $modelUser = new App_Model_Db_Table_User(); $modelUser->update($data, "kopel='" . $rowset->uid . "'"); $aResult['isError'] = true; $aResult['msg'] = 'Invoice sudah tidak bisa di renew karena tanggal expire < dari tanggal sekarang, <br>silahkan anda buat baru'; } else { $rowInvoice->expirationDate = $expiredDate; $rowInvoice->save(); $rowset->isPaid = 'R'; // status renew $rowset->save(); $notes = date("Y-m-d h:i:s") . " - Renew invoice:" . $id; $data = array('notes' => new Zend_Db_Expr("CONCAT(ifnull(notes,''),' \n{$notes}')")); $modelUser = new App_Model_Db_Table_User(); $modelUser->update($data, "kopel='" . $rowset->uid . "'"); $aResult['isError'] = true; $aResult['msg'] = 'Invoice has been updated'; } } else { $aResult['isError'] = true; $aResult['msg'] = 'Lamanya berlangganan kosong'; } } else { $aResult['isError'] = true; $aResult['msg'] = 'Invalid Invoice ID'; } echo Zend_Json::encode($aResult); }