diff --git a/app/Controllers/Invoice.php b/app/Controllers/Invoice.php index d7f60f53..95c21b1c 100755 --- a/app/Controllers/Invoice.php +++ b/app/Controllers/Invoice.php @@ -390,7 +390,6 @@ class Invoice extends BaseController // Handle invoice creation or update $invoice_id = $this->create_or_update_invoice($invoice_id, $msg_flag_name); - // Handle invoice items creation or update $this->create_or_update_invoice_items($invoice_id); $update_invoice_numbering = [ @@ -433,17 +432,20 @@ public function create_or_update_invoice($invoice_id, $msg_flag_name) $invoice_status = $this->request->getPost('status'); $customer_id = (int)$this->request->getPost('customer_name'); $invoiceType = $this->request->getPost('invoice_type'); - // Prepare invoice data $data = $this->prepare_invoice_data($invoice_id, $msg_flag_name); - // Insert or update invoice based on ID if (empty($invoice_id)) { $data['created_by'] = (int)get_logged_user_id(); if ($model->insert($data, 'invoices')) { $invoice_id = $model->insertID(); - session()->setFlashdata('success', $msg_flag_name . 'has been added successfully.'); - $this->logger->info($msg_flag_name . ": Added successfully. ID = " . $invoice_id); + if($data['status'] == 'Approved'){ + session()->setFlashdata('success', $msg_flag_name . 'has been added successfully.'); + $this->logger->info($msg_flag_name . ": Added successfully. ID = " . $invoice_id); + }else{ + session()->setFlashdata('success',$msg_flag_name . 'has been added to draft successfully'); + } + } else { session()->setFlashdata('error', $msg_flag_name . 'could not be added. Please try again.'); $this->logger->error($msg_flag_name . ": Could not be added."); @@ -535,22 +537,14 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ $to_sub_date = $item['to_subscription']; //check if membership id is already set for the customer - $membership = $subModel->check_existing_membership_id($customer_id); - //dd($membership); - if (count($membership)>0){ - $member = (array)$membership[0]; - //dd($member); - $membership_id = $member['membership_id']; - //dd($membership_id); - } - else{ + $membership_id = $this->generate_membership_id(6); // To check if the generated membership is already created for another customer $result = $subModel->where('membership_id',$membership_id)->findAll(); if (count($result)>0){ $membership_id = $this->generate_membership_id(6); } - } + // Prepare subscription data $subscription_data = [ @@ -943,7 +937,8 @@ public function create_or_update_subscription($invoice_id,$invoice_status, $msg_ $htmlFooter = '
' . $value->billing_address . '
' : ''; } ?> - = $value->bmobile ? "Phone : +91" . $value->bmobile . " ." : ($value->mobile_no ? "Phone : +91" . $value->mobile_no . " ." : "") ?>' . $value->shipping_address . '
' : ''; } ?> - = $value->smobile ? "Phone : +91" . $value->smobile . " ." : "" ?>