diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 711fe001..33fdc897 100755 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -507,6 +507,20 @@ public function create_or_update_invoice_items($invoice_id) { $this->save_invoice_item($invoice_id, $this->request->getPost(), (int)$this->request->getVar('product')); } + +public function generate_membership_id($length = 6) { + $characters = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'; + $charactersLength = strlen($characters); + $randomString = ''; + + for ($i = 0; $i < $length; $i++) { + $randomIndex = random_int(0, $charactersLength - 1); + $randomString .= $characters[$randomIndex]; + } + + return $randomString; +} + public function create_or_update_subscription($invoice_id, $msg_flag_name = null) { $model = new InvoiceModel(); @@ -519,10 +533,10 @@ public function create_or_update_subscription($invoice_id, $msg_flag_name = null $product_id = $item['product']; $from_sub_date = $item['from_subscription']; $to_sub_date = $item['to_subscription']; - $membership_id =random_int(100000, 999999); + $membership_id = $this->generate_membership_id(6); $result = $subModel->where('membership_id',$membership_id)->findAll(); if (count($result)>0){ - $membership_id = random_int(100000,999999); + $membership_id = $this->generate_membership_id(6); } // Prepare subscription data $subscription_data = [ @@ -541,6 +555,7 @@ public function create_or_update_subscription($invoice_id, $msg_flag_name = null $model->insertSubscriptionData($subscription_data); } } + ## For Updating Events Details .. public function update_number_formatting($update_events) diff --git a/app/Controllers/Payment.php b/app/Controllers/Payment.php index 8d0877dc..937ecddf 100644 --- a/app/Controllers/Payment.php +++ b/app/Controllers/Payment.php @@ -2,6 +2,7 @@ namespace App\Controllers; +use App\Models\BooksModel; use App\Models\CustomerModel; use App\Models\InvoiceModel; use App\Models\TransactionModel; @@ -22,17 +23,23 @@ class Payment extends BaseController { $model = new CustomerModel(); $model2 = new SubscriptionModel(); + $bookModel = new BooksModel(); if ($membership_id != null){ + $customer_id = $model2->select('customer_id')->where('membership_id',$membership_id)->first(); $customer_details = $model->get_customer_details_by_customer_id($customer_id); $scheme = $model2->get_subscription_details_by_membership_id($membership_id); //var_dump($customer_details);die(); + $price = $bookModel->select('price')->where('book_id', 3)->first(); + $amount = $price['price']; + log_message('debug','amount is '.$amount); $response = [ 'customer_details' => $customer_details, 'scheme' => $scheme, 'membership_id' =>$membership_id, - 'CustomerID' =>$customer_id + 'CustomerID' =>$customer_id, + 'amount' =>$amount ]; //var_dump($response);die(); return view('subscription_renewal',$response); @@ -49,10 +56,13 @@ class Payment extends BaseController $customer_id = $model2->select('customer_id')->where('membership_id',$membership_id)->first(); $customer_details = $model->get_customer_details_by_customer_id($customer_id); log_message('info','inside the method post'); + $price = $bookModel->select('price')->where('book_id', 3)->first(); + $amount = $price['price']; $response = [ 'customer_details' => $customer_details, 'scheme' => $scheme, - 'CustomerID' =>$customer_id + 'CustomerID' =>$customer_id, + 'amount' =>$amount ]; return $this->response->setJSON($response); } @@ -142,7 +152,7 @@ public function payment_failure(){ ]; $model4 = new TransactionModel(); - $model4->save($paramList); + $model4->insert($paramList); return view('/payment_failure'); } @@ -216,31 +226,18 @@ public function payment_success() { $db->table('invoiceitems')->insert($requestData); $model3 = new SubscriptionModel(); - $id_exist = $model3->where('customer_id',$customer_id)->first(); - if (count($id_exist)>0){ - $subscriptionData = [ - 'scheme_id' =>3, - 'customer_id' => $customer_id, - 'invoice_id' => $invoice_id, - 'from_subscription'=>$fsubscription, - 'to_subscription'=>$tsubscription, - 'is_renew' => 1, - 'business_id'=>2 - - ]; - $db->table('subscription')->where('customer_id', $customer_id)->update($subscriptionData); - }else{ - $subscriptionData = [ - 'scheme_id' =>3, - 'customer_id' => $customer_id, - 'invoice_id' => $invoice_id, - 'from_subscription'=>$fsubscription, - 'to_subscription'=>$tsubscription, - 'is_renew' =>0, - 'business_id'=>2 - ]; + $subscriptionData = [ + 'scheme_id' =>3, + 'customer_id' => $customer_id, + 'invoice_id' => $invoice_id, + 'from_subscription'=>$fsubscription, + 'to_subscription'=>$tsubscription, + 'is_renew' => 1, + 'business_id'=>2, + 'status' =>1 + ]; $db->table('subscription')->insert($subscriptionData); - } + $paramList = [ 'BANKTXNID' => $this->request->getVar('BANKTXNID'), diff --git a/app/Models/SubscriptionModel.php b/app/Models/SubscriptionModel.php index f89fd459..955f8ea9 100755 --- a/app/Models/SubscriptionModel.php +++ b/app/Models/SubscriptionModel.php @@ -344,14 +344,13 @@ public function getQueryforSubscriptionDetailsBySchemeName($flag,$condition, $va $builder->select('subscription.from_subscription, subscription.to_subscription, subscription.scheme_id,books.price ,books.short_code'); $builder->join('books', 'subscription.scheme_id = books.book_id'); $builder->where('subscription.membership_id', $membership_id); + $builder->where('subscription.status',1); $result = $builder->get()->getRowArray(); return $result; } - - } diff --git a/app/Views/subscription_renewal.php b/app/Views/subscription_renewal.php index b7cb0cea..fdf4737d 100644 --- a/app/Views/subscription_renewal.php +++ b/app/Views/subscription_renewal.php @@ -60,7 +60,7 @@ - + >