From bc41e5173ac6b0988f6bdf34b515c5202f5d605f Mon Sep 17 00:00:00 2001 From: VE10-Sanjeev Date: Tue, 19 Nov 2024 11:17:42 +0000 Subject: [PATCH] FIX_Draft implementation for subcription --- app/Controllers/Invoice.php | 7 ++++--- app/Controllers/Notifications.php | 1 + app/Models/InvoiceModel.php | 24 ++++++++++++++++++++---- 3 files changed, 25 insertions(+), 7 deletions(-) diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index 596fe667..c5633380 100755 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -405,7 +405,7 @@ class Invoice extends BaseController // Handle subscription if invoice type is subscription if ((int)$invoiceType === 2) { - $this->create_or_update_subscription($invoice_id, $msg_flag_name); + $this->create_or_update_subscription($invoice_id,$invoice_status, $msg_flag_name); } // Send notification if invoice is approved @@ -521,7 +521,7 @@ public function generate_membership_id($length = 6) { return $randomString; } -public function create_or_update_subscription($invoice_id, $msg_flag_name = null) +public function create_or_update_subscription($invoice_id,$invoice_status, $msg_flag_name = null) { $model = new InvoiceModel(); $subModel = new SubscriptionModel(); @@ -547,13 +547,14 @@ public function create_or_update_subscription($invoice_id, $msg_flag_name = null 'to_subscription' => $to_sub_date, 'business_id' => get_business_id(), 'created_by' => get_logged_user_id(), + 'updated_by' => get_logged_user_id(), 'is_renew' => $renewal, 'membership_id'=>$membership_id, 'status' =>1 ]; // Insert the subscription data - $model->insertSubscriptionData($subscription_data); + $model->insertSubscriptionData($subscription_data,$invoice_status); } } diff --git a/app/Controllers/Notifications.php b/app/Controllers/Notifications.php index 3ee16d89..b341b87b 100755 --- a/app/Controllers/Notifications.php +++ b/app/Controllers/Notifications.php @@ -596,6 +596,7 @@ class Notifications extends BaseController } $db = \Config\Database::connect(); $queryResult = $db->query($modifiedQuery)->getResultArray(); + $notification = new NotificationHelper(); if (empty($queryResult)) { diff --git a/app/Models/InvoiceModel.php b/app/Models/InvoiceModel.php index 540e2a58..a19d9b1f 100755 --- a/app/Models/InvoiceModel.php +++ b/app/Models/InvoiceModel.php @@ -348,13 +348,29 @@ public function getJoinedData($where, $orderby = []) ->getResult(); return $data; - - return $data; } -public function insertSubscriptionData($data) +public function insertSubscriptionData($data,$invoice_status) { - return $this->db->table('subscription')->insert($data); + if (!empty($data)) { + $invoice_id = $data['invoice_id']; + $customer_id = $data['customer_id']; + $scheme_id = $data['scheme_id']; + // $data['isactive'] = $invoice_status !== 'Draft' ? 0 : 1 ; + + $where = ['invoice_id' => $invoice_id,'customer_id' => $customer_id,'scheme_id' => $scheme_id]; + + $query = $this->db->table('subscription')->select('sub_id')->where($where)->get()->getRow(); + + if (!empty($query)) { + unset($data['created_by']); + return $this->db->table('subscription')->where('sub_id', $query->sub_id)->update($data); + } else { + unset($data['updated_by']); + return $this->db->table('subscription')->insert($data); + } + } + return false; } // ***********************REPORT**********************