Invoice ANd Notification : ps
This commit is contained in:
parent
2c8f40a69e
commit
50ca4dcfa8
@ -115,8 +115,8 @@ define('order_column', ["invoice_id","wp_api_order_id","invoice_child_id"]);
|
||||
define('order_child','invoiceitems');
|
||||
define('order_child_column', ["invoice_id","wp_api_line_items_id","customer_id"]);
|
||||
|
||||
define('WAAI_TOKEN', '650be030cedb3');
|
||||
define('WAAI_INSTANCE', '650C383B67BC7');
|
||||
define('WAAI_TOKEN', '65156a8cc4358');
|
||||
define('WAAI_INSTANCE', '65156ADE3E24F');
|
||||
define('SEND_WAAI_URL', 'https://waai.in/api/send');
|
||||
|
||||
|
||||
|
||||
@ -1,217 +1,262 @@
|
||||
<?php
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use App\Models\EventModel;
|
||||
use App\Models\CustomerModel;
|
||||
use App\Models\InvoiceModel;
|
||||
|
||||
use App\Helpers\NotificationHelper;
|
||||
|
||||
use Mpdf\Mpdf;
|
||||
|
||||
class Invoice extends BaseController
|
||||
{
|
||||
{
|
||||
## For Invoice Listing..
|
||||
public function index()
|
||||
{
|
||||
helper('session');
|
||||
if (is_session_active()) {
|
||||
$session_role = get_user_role();
|
||||
$session_bid = get_business_id();
|
||||
|
||||
|
||||
if (!empty($session_role) && $session_role !== "sadmin") {
|
||||
$where = ['I.business_id'=>(int)$session_bid,'I.isactive' => 1];
|
||||
}else{ $where = ['I.business_id != '=>NULL,'I.isactive != ' => NULL];}
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$data['page_name'] = 'Invoice Details';
|
||||
$data['invoice'] = $model->getJoinedData($where,['status']);
|
||||
// print_r($data);die();
|
||||
$this->render_page('invoice_list', $data);
|
||||
}else {
|
||||
return redirect()->to('login');
|
||||
$this->logger->info("Invoice: Listing In Admin BID = " . $session_bid);
|
||||
$where = ['I.business_id' => (int)$session_bid, 'I.isactive' => 1];
|
||||
} else {
|
||||
$this->logger->info("Invoice: Listing In the Super-Admin ");
|
||||
$where = ['I.business_id != ' => NULL, 'I.isactive != ' => NULL];
|
||||
}
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$data['page_name'] = 'Invoice Details';
|
||||
$data['invoice'] = $model->getJoinedData($where, ['status']);
|
||||
$this->logger->info("Invoice: Listing Count ." . count($data['invoice']));
|
||||
$this->render_page('invoice_list', $data);
|
||||
} else {
|
||||
return redirect()->to('login');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
## To Load Invoice ADD/EDIT page...
|
||||
public function new_invoice($id)
|
||||
{
|
||||
helper('session');
|
||||
|
||||
$model = new InvoiceModel();
|
||||
$where = ['business_id'=>(int)get_business_id()];
|
||||
// Get customer names for the dropdown
|
||||
$data['customers'] = $model->getData('customers',$where);
|
||||
$data['events']= $model->getData('events',$where);
|
||||
$data['books']= $model->getData('books',$where);
|
||||
$where = ['business_id' => (int)get_business_id()];
|
||||
|
||||
## Get customer-names for the dropdown , events-details and books-details
|
||||
$data['customers'] = $model->getData('customers', $where);
|
||||
$data['events'] = $model->getData('events', $where);
|
||||
$data['books'] = $model->getData('books', $where);
|
||||
|
||||
if ($id === '0') {
|
||||
$this->logger->info("Invoice: In Add Page");
|
||||
$data['page_name'] = 'Add Invoice Details';
|
||||
$data['invoice_details'] = [];
|
||||
$data['invoice_item_details'] = [];
|
||||
} else if ($id !== '0') {
|
||||
$this->logger->info("Invoice: In Edit Page ID =" . $id);
|
||||
$data['page_name'] = 'Edit Invoice Details';
|
||||
$data['invoice_details'] = $model->where(['invoice_id' => $id,'isactive' => 1])->first();
|
||||
$data['invoice_details'] = $model->where(['invoice_id' => $id, 'isactive' => 1])->first();
|
||||
$data['invoice_item_details'] = $this->get_invoice_item($id);
|
||||
}
|
||||
$this->render_page('invoice_form', $data);
|
||||
}
|
||||
|
||||
|
||||
## For Ajax Call To Fetch/Retrive All Address Details Based On Customer...
|
||||
public function load_details1()
|
||||
{
|
||||
|
||||
$id = $this->request->getPost('selectedValue');
|
||||
$where = ['isactive' => 1, 'customer_id' => (int)$id];
|
||||
$where['address_type'] = 1;
|
||||
$data['customer_billing'] = $this->get_customer_address($where,[]);
|
||||
$select = ["customer_address_id","CONCAT(address_1,' ',address_2) as address"];
|
||||
$data['customer_billing'] = $this->get_customer_address($where, []);
|
||||
$select = ["customer_address_id", "CONCAT(address_1,' ',address_2) as address"];
|
||||
$where['address_type'] = 2;
|
||||
$data['customer_shipping'] = $this->get_customer_address($where,$select);
|
||||
$data['customer_shipping'] = $this->get_customer_address($where, $select);
|
||||
return $this->response->setJSON(['data' => $data]);
|
||||
}
|
||||
|
||||
## For Ajax Call To Fetch/Retrive Shipping Address Details Only Based On Customer...
|
||||
public function load_details2()
|
||||
{
|
||||
$customer_id = $this->request->getPost('customerValue');
|
||||
$address_id = $this->request->getPost('selectedValue');
|
||||
$where = ['isactive' => 1, 'customer_id' => (int)$customer_id,'address_type'=>2,'customer_address_id'=>(int)$address_id];
|
||||
$data['customer_shipping'] = $this->get_customer_address($where,[]);
|
||||
$where = ['isactive' => 1, 'customer_id' => (int)$customer_id, 'address_type' => 2, 'customer_address_id' => (int)$address_id];
|
||||
$data['customer_shipping'] = $this->get_customer_address($where, []);
|
||||
return $this->response->setJSON(['data' => $data]);
|
||||
}
|
||||
|
||||
public function get_customer_address($where,$select){
|
||||
## For Gethering Address Details...
|
||||
public function get_customer_address($where, $select)
|
||||
{
|
||||
$model = new CustomerModel();
|
||||
$model->setTable('customer_addresses');
|
||||
if(!empty($select)){
|
||||
$model->setTable('customer_addresses');
|
||||
if (!empty($select)) {
|
||||
$address_details = $model->select($select)->where($where)->findAll();
|
||||
}else{
|
||||
} else {
|
||||
$address_details = $model->where($where)->findAll();
|
||||
}
|
||||
return $address_details;
|
||||
}
|
||||
|
||||
public function save_invoice(){
|
||||
|
||||
helper('session');
|
||||
$model = new InvoiceModel();
|
||||
|
||||
// print_r($this->request->getPost());
|
||||
// echo "<br/><br/>";
|
||||
// Array ( [customer_name] => 1 [shipping_address] => 2 [event_next_id] => 134 [event_id] => 1 [invoice_number] => NBF2023-INV-00133 [order_number] => 12 [invoice_date] => 2023-09-07 [due_date] => 2023-09-07 [item_details] => Array ( [0] => 1 ) [quantity] => Array ( [0] => 2 [1] => 2 ) [rate] => Array ( [0] => 3 [1] => 3 ) [tax] => [amount] => Array ( [0] => 5 [1] => 5 ) [itemDetails] => Array ( [0] => 1 ) [subtotal] => [discount] => 9 [total] => [terms] => i don't like... )
|
||||
$duedate = $this->request->getVar('due_date');
|
||||
$invdate = $this->request->getVar('invoice_date');
|
||||
$data = [
|
||||
'invoice_number' => $this->request->getPost('invoice_number'),
|
||||
'customer_id' => (int)$this->request->getPost('customer_name'),
|
||||
'billing_address_id' => (int)$this->request->getPost('billing_address_id'),
|
||||
'billing_address' => $this->request->getPost('billing_address'),
|
||||
'shipping_address_id' => (int)$this->request->getPost('shipping_address_id'),
|
||||
'shipping_address' => $this->request->getPost('shipping_address'),
|
||||
'invoice_date' => date("Y-m-d", strtotime($invdate)),
|
||||
'due_date' => date("Y-m-d", strtotime($duedate)),
|
||||
'subtotal' => (int)$this->request->getPost('sub_total'),
|
||||
'tax' => (int)$this->request->getPost('invoice_tax'),
|
||||
'discount'=> (int)$this->request->getPost('discount'),
|
||||
'total_amount'=> (int)$this->request->getPost('grand_total'),
|
||||
'order_number'=> $this->request->getPost('order_number'),
|
||||
'payment_method'=> 'Cash on Delivery',// "Credit Card," "Cash on Delivery," "PayPal","PayTm","Gpay"
|
||||
'payment_status'=> 'Pending',//"Paid," "Pending," "Failed," "Refunded," "Canceled," "Authorized," and "Completed."
|
||||
'event_id'=> (int)$this->request->getPost('event_id'),
|
||||
'business_id'=> (int)get_business_id(),
|
||||
'status' => $this->request->getPost('status'),
|
||||
'isactive'=> 1];
|
||||
$invoice_id = $this->request->getPost('invoice_id');
|
||||
|
||||
if (empty($invoice_id)) {
|
||||
$data['created_by'] = (int)get_logged_user_id();
|
||||
$model->insert($data);
|
||||
$IID = $model->insertID();
|
||||
// $IID = 1;
|
||||
} else {
|
||||
$data['updated_by'] = (int)get_logged_user_id();
|
||||
$model->update($invoice_id, $data);
|
||||
$IID = $invoice_id;
|
||||
// $IID = 1;
|
||||
## To insert or update the details of the invoice
|
||||
public function save_invoice()
|
||||
{
|
||||
$this->logger->info("Invoice: Insert/Update Details");
|
||||
try {
|
||||
|
||||
## Declarions
|
||||
helper('session');
|
||||
$model = new InvoiceModel();
|
||||
// Array ( [customer_name] => 1 [shipping_address] => 2 [event_next_id] => 134 [event_id] => 1 [invoice_number] => NBF2023-INV-00133 [order_number] => 12 [invoice_date] => 2023-09-07 [due_date] => 2023-09-07 [item_details] => Array ( [0] => 1 ) [quantity] => Array ( [0] => 2 [1] => 2 ) [rate] => Array ( [0] => 3 [1] => 3 ) [tax] => [amount] => Array ( [0] => 5 [1] => 5 ) [itemDetails] => Array ( [0] => 1 ) [subtotal] => [discount] => 9 [total] => [terms] => i don't like... )
|
||||
$duedate = $this->request->getVar('due_date');
|
||||
$invdate = $this->request->getVar('invoice_date');
|
||||
$invoice_status = $this->request->getPost('status');
|
||||
$invoice_id = (!empty($this->request->getPost('invoice_id'))) ? $this->request->getPost('invoice_id') : "";
|
||||
$customer_id = (int)$this->request->getPost('customer_name');
|
||||
|
||||
## Array Formation For Invoice Details..
|
||||
$data = [
|
||||
'invoice_number' => $this->request->getPost('invoice_number'),
|
||||
'customer_id' => $customer_id,
|
||||
'billing_address_id' => (int)$this->request->getPost('billing_address_id'),
|
||||
'billing_address' => $this->request->getPost('billing_address'),
|
||||
'shipping_address_id' => (int)$this->request->getPost('shipping_address_id'),
|
||||
'shipping_address' => $this->request->getPost('shipping_address'),
|
||||
'invoice_date' => (!empty($invdate)) ? date("Y-m-d", strtotime($invdate)) : NULL,
|
||||
'due_date' => (!empty($duedate)) ? date("Y-m-d", strtotime($duedate)) : NULL,
|
||||
'subtotal' => (int)$this->request->getPost('sub_total'),
|
||||
'tax' => (int)$this->request->getPost('invoice_tax'),
|
||||
'discount' => (int)$this->request->getPost('discount'),
|
||||
'total_amount' => (int)$this->request->getPost('grand_total'),
|
||||
'order_number' => $this->request->getPost('order_number'),
|
||||
'payment_method' => 'Cash on Delivery', // "Credit Card," "Cash on Delivery," "PayPal","PayTm","Gpay"
|
||||
'payment_status' => 'Pending', //"Paid," "Pending," "Failed," "Refunded," "Canceled," "Authorized," and "Completed."
|
||||
'event_id' => (int)$this->request->getPost('event_id'),
|
||||
'business_id' => (int)get_business_id(),
|
||||
'status' => $this->request->getPost('status'),
|
||||
'isactive' => 1
|
||||
];
|
||||
## Based on the invoice ID, we designated Insert or Update on Details...
|
||||
if (empty($invoice_id)) {
|
||||
$data['created_by'] = (int)get_logged_user_id();
|
||||
if ($model->insert($data)) {
|
||||
$invoice_id = $model->insertID();
|
||||
|
||||
session()->setFlashdata('success', 'Invoice has been added successfully.');
|
||||
$this->logger->info("Invoice: has been added successfully. Inserted ID = " . $invoice_id);
|
||||
} else {
|
||||
session()->setFlashdata('error', 'Invoice could not be added. Please try again.');
|
||||
$this->logger->error("Invoice: Err Occur could not be added. Please try again.");
|
||||
}
|
||||
} else {
|
||||
$data['updated_by'] = (int)get_logged_user_id();
|
||||
if ($model->update($invoice_id, $data)) {
|
||||
session()->setFlashdata('success', 'Invoice has been updated successfully.');
|
||||
$this->logger->info("Invoice: has been updated successfully. Updated ID = " . $invoice_id);
|
||||
} else {
|
||||
session()->setFlashdata('error', 'Invoice update failed. Please try again.');
|
||||
$this->logger->error("Invoice: Err Failed to update ID =" . $invoice_id);
|
||||
}
|
||||
}
|
||||
|
||||
$requestData = $this->request->getPost();
|
||||
|
||||
## Array Formation For Events Details And Updating Events also Here..
|
||||
$update_events = [
|
||||
'id' => $this->request->getPost('event_id'),
|
||||
'next_id' => $this->request->getPost('event_next_id'),
|
||||
'business_id' => get_business_id(),
|
||||
'updated_by' => get_logged_user_id()
|
||||
];
|
||||
$this->update_events($update_events);
|
||||
|
||||
|
||||
## For Invoice Item Details Insert/Update..
|
||||
$this->save_invoice_item($invoice_id, $requestData);
|
||||
|
||||
## Notification For Approve..
|
||||
if ($invoice_status == 'Approved' && !$invoice_id) {
|
||||
$this->approve_notifications((int)$invoice_id);
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Invoice: Err Occur =" . $e->getMessage());
|
||||
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
|
||||
}
|
||||
// print_r($data);
|
||||
// echo "<br/><br/>";
|
||||
$requestData = $this->request->getPost();
|
||||
$update_events=['id'=>$this->request->getPost('event_id'),
|
||||
'next_id' => $this->request->getPost('event_next_id'),
|
||||
'business_id' => get_business_id(),
|
||||
'updated_by' => get_logged_user_id()];
|
||||
$this->update_events($update_events);
|
||||
// print_r($update_events);echo "<br/><br/>";
|
||||
$this->save_invoice_item($IID,$requestData);//die();
|
||||
// print_r($IID);
|
||||
// print_r($requestData);die();
|
||||
|
||||
return redirect()->route('invoice_list');
|
||||
}
|
||||
|
||||
public function update_events($update_events){
|
||||
|
||||
## For Updating Events Details ..
|
||||
public function update_events($update_events)
|
||||
{
|
||||
// `id``event_name``business_id``updated_by``updated_on``next_id`
|
||||
$model = new InvoiceModel();
|
||||
$model->setTable('events');
|
||||
$where = ['isactive' => 1, 'id' => (int)$update_events['id'],'business_id'=>(int)$update_events['business_id'],'next_id'=>$update_events['next_id']];
|
||||
$where = ['isactive' => 1, 'id' => (int)$update_events['id'], 'business_id' => (int)$update_events['business_id'], 'next_id' => $update_events['next_id']];
|
||||
$details = $model->where($where)->findAll();
|
||||
if(empty($details)){
|
||||
$update_where = ['id' => (int)$update_events['id'],'business_id'=>(int)$update_events['business_id']];
|
||||
$update_data = ['next_id'=>$update_events['next_id'],'updated_by'=>$update_events['updated_by']];
|
||||
if (empty($details)) {
|
||||
$update_where = ['id' => (int)$update_events['id'], 'business_id' => (int)$update_events['business_id']];
|
||||
$update_data = ['next_id' => $update_events['next_id'], 'updated_by' => $update_events['updated_by']];
|
||||
$model->updateData('events', $update_data, $update_where);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
public function save_invoice_item($id,$requestData){
|
||||
|
||||
// print_r($requestData['invoice_child_id']);
|
||||
|
||||
|
||||
## To insert or update invoice item details based on invoice ID
|
||||
public function save_invoice_item($id, $requestData)
|
||||
{
|
||||
|
||||
## Get Invoice item details (to checking purpose exist or not based on invoice ID)
|
||||
$getInvoiceItemDetails = $this->get_invoice_item($id);
|
||||
$itemid = $requestData['invoice_child_id'];
|
||||
|
||||
|
||||
## Declaration
|
||||
$statement = "";
|
||||
$model = new InvoiceModel();
|
||||
$itemid = $requestData['invoice_child_id'];
|
||||
|
||||
// IF Any Missing value Means that values are Inactive here....
|
||||
if(!empty($itemid)){
|
||||
$filteringInvoiceItemIds = [];
|
||||
for ($y = 0; $y < count($getInvoiceItemDetails); $y++) {
|
||||
$filteringInvoiceItemIds[$y] = $getInvoiceItemDetails[$y]['invoice_child_id'];
|
||||
}
|
||||
|
||||
if(!empty($filteringInvoiceItemIds)){
|
||||
$A = $filteringInvoiceItemIds;
|
||||
$B = $itemid;
|
||||
$missingValues = array_diff($A,$B);
|
||||
|
||||
if(!empty($missingValues)){
|
||||
$where = ['isactive'=>1,'invoice_id'=>(int)$id];
|
||||
$model->inactiveMissingInvoiceItemDetails($where,$missingValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
// echo "<br/>....................";
|
||||
$count = count($itemid);
|
||||
$invoiceitem_arr = [];
|
||||
if($count > 0){
|
||||
for ($x = 0; $x < $count; $x++) {
|
||||
$invoiceitem_arr[$x]['invoice_id'] = $id;
|
||||
$invoiceitem_arr[$x]['product'] = (int)$requestData['item_details'][$x];
|
||||
$invoiceitem_arr[$x]['quantity'] = (int)$requestData['quantity'][$x];
|
||||
$invoiceitem_arr[$x]['tax'] = (int)$requestData['tax'][$x];
|
||||
$invoiceitem_arr[$x]['unit_price'] = (int)$requestData['rate'][$x];
|
||||
$invoiceitem_arr[$x]['subtotal'] = (int)$requestData['amount'][$x];
|
||||
$invoiceitem_arr[$x]['discount_amount'] = (int)$requestData['discount_amount'][$x];
|
||||
$invoiceitem_arr[$x]['discount_type'] =$requestData['discount_type'][$x];
|
||||
$invoiceitem_arr[$x]['created_by'] = (int)get_logged_user_id();
|
||||
$invoiceitem_arr[$x]['updated_by'] = (int)get_logged_user_id();
|
||||
$invoiceitem_arr[$x]['isactive'] = 1;
|
||||
$invoiceitem_arr[$x]['invoice_child_id'] = $itemid[$x];
|
||||
}
|
||||
$statement = $model->saveInvoiceItemDetails($invoiceitem_arr);
|
||||
## IF Any Missing value Means that values are Inactive here....
|
||||
if (!empty($itemid)) {
|
||||
$filteringInvoiceItemIds = [];
|
||||
for ($y = 0; $y < count($getInvoiceItemDetails); $y++) {
|
||||
$filteringInvoiceItemIds[$y] = $getInvoiceItemDetails[$y]['invoice_child_id'];
|
||||
}
|
||||
return $statement;
|
||||
|
||||
if (!empty($filteringInvoiceItemIds)) {
|
||||
$A = $filteringInvoiceItemIds;
|
||||
$B = $itemid;
|
||||
$missingValues = array_diff($A, $B);
|
||||
|
||||
if (!empty($missingValues)) {
|
||||
$where = ['isactive' => 1, 'invoice_id' => (int)$id];
|
||||
$model->inactiveMissingInvoiceItemDetails($where, $missingValues);
|
||||
}
|
||||
}
|
||||
}
|
||||
// echo "<br/>....................";
|
||||
$count = count($itemid);
|
||||
$invoiceitem_arr = [];
|
||||
if ($count > 0) {
|
||||
for ($x = 0; $x < $count; $x++) {
|
||||
$invoiceitem_arr[$x]['invoice_id'] = $id;
|
||||
$invoiceitem_arr[$x]['product'] = (int)$requestData['item_details'][$x];
|
||||
$invoiceitem_arr[$x]['quantity'] = (int)$requestData['quantity'][$x];
|
||||
$invoiceitem_arr[$x]['tax'] = (int)$requestData['tax'][$x];
|
||||
$invoiceitem_arr[$x]['unit_price'] = (int)$requestData['rate'][$x];
|
||||
$invoiceitem_arr[$x]['subtotal'] = (int)$requestData['amount'][$x];
|
||||
$invoiceitem_arr[$x]['discount_amount'] = (int)$requestData['discount_amount'][$x];
|
||||
$invoiceitem_arr[$x]['discount_type'] =$requestData['discount_type'][$x];
|
||||
$invoiceitem_arr[$x]['created_by'] = (int)get_logged_user_id();
|
||||
$invoiceitem_arr[$x]['updated_by'] = (int)get_logged_user_id();
|
||||
$invoiceitem_arr[$x]['isactive'] = 1;
|
||||
$invoiceitem_arr[$x]['invoice_child_id'] = $itemid[$x];
|
||||
}
|
||||
$statement = $model->saveInvoiceItemDetails($invoiceitem_arr);
|
||||
}
|
||||
return $statement;
|
||||
}
|
||||
|
||||
public function get_invoice_item($id){
|
||||
## To Retrive Invoice item details based on invoice ID
|
||||
public function get_invoice_item($id)
|
||||
{
|
||||
$model = new InvoiceModel();
|
||||
$model->setTable('invoiceitems');
|
||||
$where = ['isactive' => 1, 'invoice_id' => (int)$id];
|
||||
@ -219,108 +264,209 @@ class Invoice extends BaseController
|
||||
return $details;
|
||||
}
|
||||
|
||||
public function delete_invoice($id){
|
||||
|
||||
## To Inactive Invoice details based on invoice ID Including Invoice Item Details also
|
||||
public function delete_invoice($id)
|
||||
{
|
||||
helper('session');
|
||||
$model = new InvoiceModel();
|
||||
$where = ['isactive' => 1, 'business_id' => (int)get_business_id(),'invoice_id' => (int)$id];
|
||||
$existed = $model->where($where)->findAll();
|
||||
$session_uid = get_logged_user_id();
|
||||
try {
|
||||
$model = new InvoiceModel();
|
||||
$where = ['isactive' => 1, 'business_id' => (int)get_business_id(), 'invoice_id' => (int)$id];
|
||||
$existed = $model->where($where)->findAll();
|
||||
$this->logger->Info("Invoice : Going to Inactive ID = " . $id);
|
||||
|
||||
if ($existed) {
|
||||
$data['isactive'] = 0;
|
||||
$data['updated_by'] = get_logged_user_id();
|
||||
$model->update($id, $data);
|
||||
$getInvoiceItemDetails = $this->get_invoice_item($id);
|
||||
if ($getInvoiceItemDetails) {
|
||||
$update_where = ['invoice_id' => (int)$id];
|
||||
$model->updateData('invoiceitems', $data, $update_where);
|
||||
if ($existed) {
|
||||
$data['isactive'] = 0;
|
||||
$data['updated_by'] = get_logged_user_id();
|
||||
|
||||
if ($model->update($id, $data)) {
|
||||
session()->setFlashdata('success', 'Deleted successfully.');
|
||||
$this->logger->info("Invoice: has been Inactived successfully. Inactived ID = " . $id);
|
||||
} else {
|
||||
$this->logger->error("Invoice: Not able to Inactive ID =" . $id);
|
||||
throw new \Exception("Data Not able to Deleted");
|
||||
}
|
||||
$getInvoiceItemDetails = $this->get_invoice_item($id);
|
||||
if ($getInvoiceItemDetails) {
|
||||
$update_where = ['invoice_id' => (int)$id];
|
||||
$model->updateData('invoiceitems', $data, $update_where);
|
||||
}
|
||||
} else {
|
||||
$this->logger->error("Invoice: Does Not Exist To Inactive, ID = " . $id);
|
||||
throw new \Exception("Invoice Already Deleted");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Invoice: Err Occur = " . $e->getMessage());
|
||||
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
|
||||
}
|
||||
|
||||
return redirect()->route('invoice_list');
|
||||
}
|
||||
|
||||
## To Approve Invoice details based on invoice ID
|
||||
public function approve_invoice($id)
|
||||
{
|
||||
// Validate $id (e.g., check if it's a valid invoice ID)
|
||||
|
||||
// Update the status in the database to "Approved"
|
||||
$model = new InvoiceModel();
|
||||
$data = ['status' => 'Approved'];
|
||||
$model->update($id, $data);
|
||||
|
||||
|
||||
try {
|
||||
if (!$id) {
|
||||
throw new \Exception("Invoice can't able to Approved. Because ID can't Found");
|
||||
}
|
||||
$model = new InvoiceModel();
|
||||
helper('session');
|
||||
$where = ['isactive' => 1, 'status' => 'Approved', 'invoice_id' => (int)$id];
|
||||
$details = $model->where($where)->findAll();
|
||||
if (!empty($details)) { // change
|
||||
// print_r($details);die;
|
||||
$data = ['status' => 'Approved', 'updated_by' => get_logged_user_id()];
|
||||
if ($model->update($id, $data)) {
|
||||
$this->approve_notifications((int)$id);
|
||||
session()->setFlashdata('success', 'Invoice has been Approved Successfully.');
|
||||
$this->logger->info("Invoice: has been Approved successfully. ID = " . $id);
|
||||
} else {
|
||||
$this->logger->error("Invoice: Does Not Exist To Approved");
|
||||
throw new \Exception("Invoice can't Approved");
|
||||
}
|
||||
} else {
|
||||
$this->logger->error("Invoice: already Approved ID = " . $id);
|
||||
throw new \Exception("Invoice already Approved");
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("Invoice: Err Occur = " . $e->getMessage());
|
||||
session()->setFlashdata('error', 'Message: ' . $e->getMessage());
|
||||
}
|
||||
// Redirect back to the invoice list
|
||||
return redirect()->route('invoice_list');
|
||||
}
|
||||
|
||||
public function approve_notifications($invoice_id)
|
||||
{
|
||||
$model = new InvoiceModel();
|
||||
$where = ['I.business_id' => (int)get_business_id(), 'I.invoice_id' => $invoice_id, 'I.isactive' => 1];
|
||||
$details = $model->getJoinedData($where);
|
||||
$reference_number = "";
|
||||
$invoice_serial_number = "";
|
||||
$recipient_name = "";
|
||||
$approval_date = "";
|
||||
$approved_by = "";
|
||||
$recipient_email = "";
|
||||
$recipient_mobile = "";
|
||||
if (isset($details) && gettype($details) === 'object') {
|
||||
$details = [$details];
|
||||
$this->logger->info("Approve : Request data type = " . gettype($details));
|
||||
}
|
||||
helper('notification');
|
||||
$notification = new NotificationHelper();
|
||||
|
||||
|
||||
public function generate_invoice_pdf($id)
|
||||
{
|
||||
// Fetch the invoice data based on $invoice_id
|
||||
$model = new InvoiceModel();
|
||||
$data = $model->getInvoiceData($id);
|
||||
$invoiceItems = $model->getInvoiceItems($id);
|
||||
|
||||
// print_r($invoiceItems);die();
|
||||
foreach ($details as $rec) {
|
||||
$reference_number = $rec->order_number;
|
||||
$invoice_serial_number = $rec->invoice_number;
|
||||
$recipient_name = $rec->customer_name;
|
||||
$approval_date = $rec->updated_on;
|
||||
$approved_by = $rec->updated_by_name;
|
||||
$recipient_email = $rec->customer_email;
|
||||
$recipient_mobile = $rec->customer_mobile;
|
||||
$records['recipient'] = $rec->customer_email;
|
||||
$records['mobile'] = $rec->customer_mobile;
|
||||
}
|
||||
|
||||
// Create an mPDF object
|
||||
$mpdf = new Mpdf();
|
||||
$records['subject'] = $invoice_serial_number . " - Approval Notification";
|
||||
$records['description'] = "<html><head><title>VBP Approve Information</title></head><body>
|
||||
<p>Dear $recipient_name,</p>
|
||||
<p>    We are pleased to inform you that your Invoice has been approved.</p>
|
||||
<p><strong>Details:</strong></p>
|
||||
<ul><li>Approval Date:" . $approval_date . "</li>
|
||||
<li>Approved By:" . $approved_by . "</li>
|
||||
<li>Reference ID:" . $reference_number . "</li>
|
||||
</ul><br>
|
||||
<p>Best regards,</p>
|
||||
<ul style='list-style: none;'>
|
||||
<li>VijayaBharathamBooks,</li>
|
||||
<li>Sri Kasi, 12, M.V. Naidu Street, Chetpet, Chennai.</li>
|
||||
<li>Call Us: +91 89391 49466</li>
|
||||
<li>Email Us: contact@vijayabharathambooks.com</li></body></html>";
|
||||
|
||||
// Set PDF properties
|
||||
$mpdf->SetTitle('Invoice');
|
||||
$mpdf->SetAuthor('VBP');
|
||||
$mpdf->SetCreator('');
|
||||
$template = "Dear " . $recipient_name . ",\r\r\n\nYour Invoice has been approved.\n\nDetails:\r\n- Approval Date: " . $approval_date . "\r\n- Approved By: " . $approved_by . "\r\n- Reference ID: " . $reference_number . "\r\n\nBest regards,\nVijayaBharathamBooks,\nSri Kasi, 12, M.V. Naidu Street, Chetpet, Chennai.\nCall Us: +91 89391 49466\nEmail Us: contact@vijayabharathambooks.com";
|
||||
|
||||
// Generate the PDF content (HTML)
|
||||
if ($data[0]->status === 'Draft') {
|
||||
// Set the watermark text and options
|
||||
$mpdf->SetWatermarkText('Draft');
|
||||
$mpdf->showWatermarkText = true;
|
||||
$params = (object) Null;
|
||||
$params->number = (int)'91' . $recipient_mobile;
|
||||
$params->type = "text";
|
||||
$params->message = $template;
|
||||
$params->instance_id = WAAI_INSTANCE;
|
||||
$params->access_token = WAAI_TOKEN;
|
||||
|
||||
$email_result = $notification->sendEmail($records);
|
||||
$this->logger->info("Invoice: approve notification = " . json_encode($email_result));
|
||||
$whatsapp_result = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params);
|
||||
$this->logger->info("Invoice: approve notification = " . json_encode($whatsapp_result));
|
||||
}
|
||||
|
||||
// Generate the PDF content (HTML) with data
|
||||
$html = view('invoice_pdf_template', ['data' => $data, 'invoiceItems' => $invoiceItems]);
|
||||
|
||||
// Load HTML into the mPDF instance
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// Output the PDF to the browser for download
|
||||
$mpdf->Output('invoice_' . $id . '.pdf', 'D');
|
||||
|
||||
|
||||
|
||||
}
|
||||
public function print_address($id)
|
||||
{
|
||||
// Fetch the invoice data based on $id
|
||||
$model = new InvoiceModel();
|
||||
$invoiceData = $model->getInvoiceData($id);
|
||||
// print_r($invoiceData);die();
|
||||
$mpdf = new \Mpdf\Mpdf();
|
||||
$mpdf->SetTitle('Customer Address');
|
||||
$mpdf->SetAuthor('Your Company Name');
|
||||
$mpdf->SetCreator('');
|
||||
|
||||
// Generate the PDF content (HTML) with customer and address data
|
||||
$html = view('address_pdf_template', ['invoiceData' => $invoiceData]);
|
||||
|
||||
|
||||
// Load the mPDF library
|
||||
|
||||
|
||||
// Set PDF properties
|
||||
|
||||
## To Generate Invoice PDF based on invoice ID
|
||||
public function generate_invoice_pdf($id)
|
||||
{
|
||||
// Fetch the invoice data based on $invoice_id
|
||||
$model = new InvoiceModel();
|
||||
$data = $model->getInvoiceData($id);
|
||||
$invoiceItems = $model->getInvoiceItems($id);
|
||||
|
||||
// Load HTML content into mPDF
|
||||
$mpdf->WriteHTML($html);
|
||||
// print_r($invoiceItems);die();
|
||||
|
||||
// Output the PDF for download
|
||||
$pdfFileName = 'customer_address_' . $id . '.pdf';
|
||||
$mpdf->Output($pdfFileName, 'D');
|
||||
|
||||
// Create an mPDF object
|
||||
$mpdf = new Mpdf();
|
||||
|
||||
// Set PDF properties
|
||||
$mpdf->SetTitle('Invoice');
|
||||
$mpdf->SetAuthor('VBP');
|
||||
$mpdf->SetCreator('');
|
||||
|
||||
// Generate the PDF content (HTML)
|
||||
if ($data[0]->status === 'Draft') {
|
||||
// Set the watermark text and options
|
||||
$mpdf->SetWatermarkText('Draft');
|
||||
$mpdf->showWatermarkText = true;
|
||||
}
|
||||
|
||||
// Generate the PDF content (HTML) with data
|
||||
$html = view('invoice_pdf_template', ['data' => $data, 'invoiceItems' => $invoiceItems]);
|
||||
|
||||
// Load HTML into the mPDF instance
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// Output the PDF to the browser for download
|
||||
$mpdf->Output('invoice_' . $id . '.pdf', 'D');
|
||||
}
|
||||
public function print_address($id)
|
||||
{
|
||||
// Fetch the invoice data based on $id
|
||||
$model = new InvoiceModel();
|
||||
$invoiceData = $model->getInvoiceData($id);
|
||||
// print_r($invoiceData);die();
|
||||
$mpdf = new \Mpdf\Mpdf();
|
||||
$mpdf->SetTitle('Customer Address');
|
||||
$mpdf->SetAuthor('Your Company Name');
|
||||
$mpdf->SetCreator('');
|
||||
|
||||
// Generate the PDF content (HTML) with customer and address data
|
||||
$html = view('address_pdf_template', ['invoiceData' => $invoiceData]);
|
||||
|
||||
|
||||
// Load the mPDF library
|
||||
|
||||
|
||||
// Set PDF properties
|
||||
|
||||
|
||||
// Load HTML content into mPDF
|
||||
$mpdf->WriteHTML($html);
|
||||
|
||||
// Output the PDF for download
|
||||
$pdfFileName = 'customer_address_' . $id . '.pdf';
|
||||
$mpdf->Output($pdfFileName, 'D');
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
// public function generate_invoice_pdf($id)
|
||||
// {
|
||||
// // Load the mPDF library
|
||||
@ -352,4 +498,3 @@ public function print_address($id)
|
||||
// // Fetch invoice items related to the given invoice ID
|
||||
// return $this->db->table('invoice_items')->where('invoice_id', $invoiceId)->get()->getResult();
|
||||
// }
|
||||
|
||||
|
||||
@ -2,152 +2,63 @@
|
||||
|
||||
namespace App\Controllers;
|
||||
|
||||
use CodeIgniter\RESTful\ResourceController;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
use App\Models\ApiIntegrationModel;
|
||||
use App\Helpers\NotificationHelper;
|
||||
|
||||
class Notifications extends BaseController
|
||||
{
|
||||
// Define global variables as class properties
|
||||
// protected $instance_id = '';
|
||||
// protected $instance_id = "650C050D9D849";
|
||||
// protected $access_token = "650be030cedb3";
|
||||
protected $instance_id = "";
|
||||
protected $access_token = "";
|
||||
|
||||
## Whatsapp Section :
|
||||
// public function get_whatsapp_instance() {
|
||||
// helper('apiIntegration');
|
||||
// $instance_id = "";
|
||||
// try {
|
||||
// $response = get_whatsapp_instance($this->access_token);
|
||||
// $this->logger->info("Whatsapp : get instance response type = ".gettype($response));
|
||||
// if(isset($response) && !empty($response)){
|
||||
// $this->logger->info("Whatsapp : get instance message = ".$response->message);
|
||||
// if($response->status == "success"){
|
||||
// $instance_id = $response->instance_id;
|
||||
// $this->logger->info("Whatsapp : instance id = ".$response->instance_id);
|
||||
// }
|
||||
// else{
|
||||
// $this->logger->error("Whatsapp : get instance Err = ".$response->error." Err Message = ".$response->error_msg);
|
||||
// throw new \Exception("Err = ".$response->error." Err Message = ".$response->error_msg);
|
||||
// }
|
||||
// }
|
||||
// } catch (\Exception $e) {
|
||||
// $this->logger->error("Whatsapp : get instance exception", ['exception' => $e]);
|
||||
// }
|
||||
// return $instance_id;
|
||||
// }
|
||||
// public function get_whatsapp_instance($url){
|
||||
// $response = get_whatsapp_instance($url);
|
||||
// }
|
||||
|
||||
public function send_whatsapp_message() {
|
||||
helper('apiIntegration');
|
||||
$params = (object) Null;
|
||||
try {
|
||||
$this->logger->info("Whatsapp : sending message instance id = ".$this->instance_id);
|
||||
$params->number = 916369084112;
|
||||
$params->type = "text";
|
||||
$params->message = "TestingFromVBPYUIO";
|
||||
$params->instance_id = WAAI_TOKEN;
|
||||
$params->access_token = WAAI_INSTANCE;
|
||||
$this->logger->info("Whatsapp : sending message request type b4 = ".gettype($params));
|
||||
//$url = "https://waai.in/api/send?number=916369084112&type=text&message=helper&instance_id=650C383B67BC7&access_token=650be030cedb3";
|
||||
$url = "https://waai.in/api/send";
|
||||
$message = perform_whatsapp_request($url,"POST",$params);
|
||||
// https://waai.in/api/send?number=91639084112&type=text&message=helper&instance_id=650C383B67BC7&access_token=650be030cedb3/r/n{"status":"success","message":{"key":{"remoteJid":"91639084112@c.us","fromMe":true,"id":"BAE540383CE30F06"},"message":{"extendedTextMessage":{"text":"helper"}},"messageTimestamp":"1695362314"}}
|
||||
// {"status":"success","message":{"key":{"remoteJid":"916369084112@c.us","fromMe":true,"id":"BAE500BBE10A0AC0"},"message":{"extendedTextMessage":{"text":"TestingFromVBP"}},"messageTimestamp":"1695362020"}}
|
||||
// {"status":"error","message":"Access token is required"}
|
||||
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("An error occurred: " . $e->getMessage());
|
||||
$message = "An error occurred: " . $e->getMessage();
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
|
||||
## Email Section :
|
||||
public function mail_custom_notifications()
|
||||
{ $successMessage = session()->getFlashdata('success');
|
||||
$validationErrors = session()->getFlashdata('error');
|
||||
$data['page_name'] = 'Custom Notifications';
|
||||
$request = \Config\Services::request();
|
||||
if($request->is('post')){
|
||||
{
|
||||
$successMessage = session()->getFlashdata('success');
|
||||
$validationErrors = session()->getFlashdata('error');
|
||||
$request = \Config\Services::request();
|
||||
if ($request->is('post')) {
|
||||
$records = $request->getVar();
|
||||
$cc = isset($records['carboncopy']) ? $records['carboncopy'] : '';
|
||||
$bcc = isset($records['blindcarboncopy']) ? $records['blindcarboncopy'] : '';
|
||||
try {
|
||||
|
||||
$email = \Config\Services::email();
|
||||
$email->setTo($records['recipient']);
|
||||
$email->setFrom('no-reply@tripapprovaltool.com', isset($records['company'])?$records['company']:"VBP");
|
||||
$email->setSubject($records['subject']);
|
||||
$email->setMessage($records['description']);
|
||||
|
||||
if (!empty($cc)) {
|
||||
$ccRecipients = explode(',', $cc);
|
||||
foreach ($ccRecipients as $ccRecipient) {
|
||||
$email->setCC(trim($ccRecipient));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($bcc)) {
|
||||
$bccRecipients = explode(',', $bcc);
|
||||
foreach ($bccRecipients as $bccRecipient) {
|
||||
$email->setBCC(trim($bccRecipient));
|
||||
}
|
||||
}
|
||||
|
||||
if ($email->send()) {
|
||||
$this->logger->info('Email sent successfully');
|
||||
$successMessage = 'Email sent successfully';
|
||||
$data['successMessage'] = $successMessage;
|
||||
} else {
|
||||
throw new \Exception('Email not sent. Please try again.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Error sending email: ' . $e->getMessage());
|
||||
$validationErrors = 'Error sending email: ' . $e->getMessage();
|
||||
$data['validationErrors'] = $validationErrors;
|
||||
helper('notification');
|
||||
$notification = new NotificationHelper();
|
||||
$data = $notification->sendEmail($records);
|
||||
if (isset($data['error'])) {
|
||||
session()->setFlashdata('error', 'Message: ' . $data['error']);
|
||||
}
|
||||
if (isset($data['success'])) {
|
||||
session()->setFlashdata('success', 'Message: ' . $data['success']);
|
||||
}
|
||||
}
|
||||
$data['page_name'] = 'Custom Notifications';
|
||||
$this->render_page('notifications_form', $data);
|
||||
}
|
||||
|
||||
$this->render_page('notifications_form', $data);
|
||||
}
|
||||
|
||||
public function whatsapp_custom_notifications(){
|
||||
$successMessage = session()->getFlashdata('success');
|
||||
$validationErrors = session()->getFlashdata('error');
|
||||
$data['page_name'] = 'Custom Notifications';
|
||||
helper('apiIntegration');
|
||||
$request = \Config\Services::request();
|
||||
if($request->is('post')){
|
||||
public function whatsapp_custom_notifications()
|
||||
{
|
||||
$request = \Config\Services::request();
|
||||
if ($request->is('post')) {
|
||||
$records = $request->getVar();
|
||||
$params = (object) Null;
|
||||
$this->access_token = "650be030cedb3";
|
||||
$this->instance_id = "650C383B67BC7";
|
||||
$this->logger->info("Whatsapp : sending message instance id = ".$this->instance_id);
|
||||
$this->logger->info("Whatsapp : sending message instance id = " . WAAI_INSTANCE);
|
||||
try {
|
||||
$this->logger->info("Whatsapp : sending message instance id = ".$this->instance_id);
|
||||
$params->number = (int)'91'.$records['mobile'];
|
||||
$this->logger->info("Whatsapp : sending message instance id = " . WAAI_INSTANCE);
|
||||
$params->number = (int)'91' . $records['mobile'];
|
||||
$params->type = $records['type'] == "" ? "text" : $records['type'];
|
||||
$params->instance_id = WAAI_INSTANCE;
|
||||
$params->access_token = WAAI_TOKEN;
|
||||
$params->message = $records['description'];
|
||||
if($records['type'] == 'media'){ $params->media_url = $records['media_url'];}
|
||||
$this->logger->info("Whatsapp : sending message request type b4 = ".gettype($params));
|
||||
$successMessage = perform_whatsapp_request(SEND_WAAI_URL,"POST",$params);
|
||||
$this->logger->info("Whatsapp : Reponse = ".$successMessage);
|
||||
$data['successMessage'] = $successMessage;
|
||||
if ($records['type'] == 'media') {
|
||||
$params->media_url = $records['media_url'];
|
||||
}
|
||||
$this->logger->info("Whatsapp : sending message request type b4 = " . gettype($params));
|
||||
helper('notification');
|
||||
$notification = new NotificationHelper();
|
||||
$success = $notification->sendWhatsAppMessage(SEND_WAAI_URL, "POST", $params);
|
||||
session()->setFlashdata('success', 'Message : ' . $success);
|
||||
$this->logger->info("Whatsapp : Reponse = " . $success);
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error("An error occurred: " . $e->getMessage());
|
||||
$validationErrors = "An error occurred: " . $e->getMessage();
|
||||
$data['validationErrors'] = $validationErrors;
|
||||
$this->logger->error("Whatsapp : Exception Message = " . $e->getMessage() . "<br> File: " . $e->getFile() . "<br> Line: " . $e->getLine() . "<br>");
|
||||
$error = "An error occurred: " . $e->getMessage();
|
||||
session()->setFlashdata('error', 'Message: ' . $error);
|
||||
}
|
||||
}
|
||||
$this->render_page('notifications_form', $data);
|
||||
}
|
||||
$data['page_name'] = 'Custom Notifications';
|
||||
$this->render_page('notifications_form', $data);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -17,7 +17,7 @@ class Users extends BaseController
|
||||
$session_bid = get_business_id();
|
||||
|
||||
if (!empty($session_role) && $session_role !== "sadmin") {
|
||||
$this->logger->info("Users: Listing In admin role .");
|
||||
$this->logger->info("Users: Listing In admin role . BID = ".$session_bid);
|
||||
$where = ['users.business_id' => (int)$session_bid, 'users.isactive' => 1];
|
||||
} else {
|
||||
$this->logger->info("Users: Listing In Super-admin role .");
|
||||
|
||||
109
app/Helpers/NotificationHelper.php
Normal file
109
app/Helpers/NotificationHelper.php
Normal file
@ -0,0 +1,109 @@
|
||||
<?php
|
||||
|
||||
// app/Helpers/NotificationHelper.php
|
||||
|
||||
namespace App\Helpers;
|
||||
|
||||
class NotificationHelper
|
||||
{
|
||||
protected $email;
|
||||
protected $logger;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->email = service('email');
|
||||
$this->logger = service('logger');
|
||||
}
|
||||
|
||||
public function sendEmail($records)
|
||||
{
|
||||
$this->logger->info('Helper : Email');
|
||||
$cc = isset($records['carboncopy']) ? $records['carboncopy'] : '';
|
||||
$bcc = isset($records['blindcarboncopy']) ? $records['blindcarboncopy'] : '';
|
||||
try {
|
||||
$this->email->setTo($records['recipient']);
|
||||
$this->email->setFrom('no-reply@tripapprovaltool.com', isset($records['company'])?$records['company']:"VBP");
|
||||
$this->email->setSubject($records['subject']);
|
||||
$this->email->setMessage($records['description']);
|
||||
|
||||
|
||||
if (!empty($cc)) {
|
||||
$ccRecipients = explode(',', $cc);
|
||||
foreach ($ccRecipients as $ccRecipient) {
|
||||
$this->email->setCC(trim($ccRecipient));
|
||||
}
|
||||
}
|
||||
|
||||
if (!empty($bcc)) {
|
||||
$bccRecipients = explode(',', $bcc);
|
||||
foreach ($bccRecipients as $bccRecipient) {
|
||||
$this->email->setBCC(trim($bccRecipient));
|
||||
}
|
||||
}
|
||||
|
||||
if ($this->email->send()) {
|
||||
$message['success'] = 'Email sent successfully';
|
||||
$this->logger->info('Email sent successfully');
|
||||
} else {
|
||||
throw new \Exception('Email sending failed.');
|
||||
}
|
||||
} catch (\Exception $e) {
|
||||
$this->logger->error('Email Error: ' . $e->getMessage());
|
||||
$message['error'] = 'Email Error : ' . $e->getMessage();
|
||||
}
|
||||
return $message;
|
||||
}
|
||||
|
||||
public function sendWhatsAppMessage($url,$method,$data)
|
||||
{
|
||||
try{
|
||||
$this->logger->info('Helper : Whatsapp');
|
||||
$curl = curl_init();
|
||||
$headers = array('Content-Type:application/json');
|
||||
curl_setopt( $curl,CURLOPT_URL, $url);
|
||||
$this->logger->info('Helper : Whatsapp url = '.$url);
|
||||
switch ($method) {
|
||||
case "POST":
|
||||
curl_setopt( $curl,CURLOPT_POST, true );
|
||||
if ($data) {
|
||||
curl_setopt( $curl,CURLOPT_POSTFIELDS, json_encode($data));
|
||||
}
|
||||
break;
|
||||
case "PUT":
|
||||
curl_setopt($curl, CURLOPT_PUT, 1);
|
||||
break;
|
||||
default:
|
||||
if ($data) {
|
||||
// print_r($data);die();
|
||||
$url = sprintf("%s?%s", $url, http_build_query((array)$data));
|
||||
}
|
||||
}
|
||||
curl_setopt( $curl,CURLOPT_HTTPHEADER, $headers );
|
||||
curl_setopt( $curl,CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $curl,CURLOPT_SSL_VERIFYPEER, true );
|
||||
$curl_exec = curl_exec($curl);
|
||||
$this->logger->info('Helper : Whatsapp Reponse = '.$curl_exec);
|
||||
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($http_status === 200) {
|
||||
$result = json_decode($curl_exec);
|
||||
if ($result->status === "error") {
|
||||
$this->logger->error('Helper : Whatsapp Err occur = '.$result->message);
|
||||
throw new \Exception($result->message);
|
||||
}else{
|
||||
$final_result = " Sended Success ";
|
||||
}
|
||||
}else{
|
||||
$curl_errno= curl_errno($curl);
|
||||
$this->logger->error('Helper : Whatsapp curl error occur = '.$curl_errno);
|
||||
throw new \Exception(" Errno returned ".$curl_errno);
|
||||
}
|
||||
curl_close($curl);
|
||||
}catch (\Exception $e) {
|
||||
$this->logger->error('Helper : Whatsapp Exception Occur = ' . $e->getMessage());
|
||||
$final_result = "Exception Errno returned".$e->getMessage()." <br/>";
|
||||
}
|
||||
return $final_result;
|
||||
}
|
||||
}
|
||||
|
||||
?>
|
||||
@ -4,50 +4,7 @@ function perform_whatsapp_request($url,$method,$data){
|
||||
// log_message('INFO',"PerformWhatsappRequest : request url = ".$url);
|
||||
// log_message('INFO',"PerformWhatsappRequest : request data type = ".$data);
|
||||
// log_message('INFO',"PerformWhatsappRequest : method = ".$method);
|
||||
try{
|
||||
$curl = curl_init();
|
||||
$headers = array('Content-Type:application/json');
|
||||
curl_setopt( $curl,CURLOPT_URL, $url);
|
||||
switch ($method) {
|
||||
case "POST":
|
||||
curl_setopt( $curl,CURLOPT_POST, true );
|
||||
if ($data) {
|
||||
curl_setopt( $curl,CURLOPT_POSTFIELDS, json_encode($data));
|
||||
}
|
||||
break;
|
||||
case "PUT":
|
||||
curl_setopt($curl, CURLOPT_PUT, 1);
|
||||
break;
|
||||
default:
|
||||
if ($data) {
|
||||
// print_r($data);die();
|
||||
$url = sprintf("%s?%s", $url, http_build_query((array)$data));
|
||||
}
|
||||
}
|
||||
curl_setopt( $curl,CURLOPT_HTTPHEADER, $headers );
|
||||
curl_setopt( $curl,CURLOPT_RETURNTRANSFER, true );
|
||||
curl_setopt( $curl,CURLOPT_SSL_VERIFYPEER, true );
|
||||
$curl_exec = curl_exec($curl);
|
||||
// log_message('INFO',"PerformWhatsappRequest : reponse = ".$curl_exec);
|
||||
$http_status = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
||||
if ($http_status === 200) {
|
||||
$result = json_decode($curl_exec);
|
||||
if ($result->status === "error") {
|
||||
// log_message('ERROR',"PerformWhatsappRequest : error = ".$result->message);
|
||||
throw new Exception($result->message);
|
||||
}else{
|
||||
$final_result = "Success";
|
||||
}
|
||||
}else{
|
||||
$curl_errno= curl_errno($curl);
|
||||
// log_message('ERROR',"PerformWhatsappRequest : curl error = ".$curl_errno);
|
||||
throw new Error("Errno returned ".$curl_errno);
|
||||
}
|
||||
curl_close($curl);
|
||||
}catch (Exception $e) {
|
||||
$final_result = "Exception Errno returned".$e->getMessage()." <br/>";
|
||||
}
|
||||
return $final_result;
|
||||
|
||||
}
|
||||
|
||||
function perform_http_request_old($method, $url, $data = false) {
|
||||
|
||||
@ -53,7 +53,7 @@ public function updateData($table, $data, $where)
|
||||
->join('business as B', 'B.business_id = I.business_id', 'left')
|
||||
->join('users as U1', 'U1.user_id = I.created_by', 'left')
|
||||
->join('users as U2', 'U2.user_id = I.updated_by', 'left')
|
||||
->select('I.invoice_id, I.invoice_number, I.customer_id,concat(C.first_name," ",C.last_name) as customer_name , I.invoice_date, I.due_date, I.subtotal, I.tax, I.discount, I.total_amount,I.status, I.payment_status, I.order_number, I.payment_method, I.event_id,E.event_name, I.business_id,B.title as business_name, I.created_on, I.created_by,concat(U1.first_name," ",U1.last_name) as created_by_name, I.updated_on, I.updated_by,concat(U2.first_name," ",U2.last_name) as updated_by_name, I.isactive')
|
||||
->select('I.invoice_id, I.invoice_number, I.customer_id,concat(C.first_name," ",C.last_name) as customer_name , I.invoice_date, I.due_date, I.subtotal, I.tax, I.discount, I.total_amount,I.status, I.payment_status, I.order_number, I.payment_method, I.event_id,E.event_name, I.business_id,B.title as business_name, I.created_on, I.created_by,concat(U1.first_name," ",U1.last_name) as created_by_name, I.updated_on, I.updated_by,concat(U2.first_name," ",U2.last_name) as updated_by_name, I.isactive,C.email as customer_email,C.mobile_no as customer_mobile')
|
||||
->where($where)
|
||||
->get()
|
||||
->getResult();
|
||||
|
||||
@ -3,7 +3,7 @@
|
||||
<div class="card">
|
||||
<div class="card-body">
|
||||
<h4 class="header-title"><?= $page_name; ?></h4>
|
||||
<p class="sub-header"> </p>
|
||||
<!-- <p class="sub-header"><?php print_r($invoice_details); ?> </p> -->
|
||||
<form method="POST" enctype="multipart/form-data" action="<?php echo base_url(); ?>save_invoice">
|
||||
<div class="form-group">
|
||||
<div class="form-row">
|
||||
@ -113,30 +113,30 @@
|
||||
<?php endforeach; ?>
|
||||
</select></td>
|
||||
<td style="width:10%;"><input type="number" class="form-control"
|
||||
id="quantity" name="quantity[]" oninput="calculateInvoice(this)" />
|
||||
id="quantity" name="quantity[]" oninput="calculateInvoice(this)" value="<?= isset($ii_details['product']) ? $ii_details['quantity'] : '' ?>" />
|
||||
</td>
|
||||
<td style="width:10%;"><input type="text" class="form-control" id="rate"
|
||||
name="rate[]" oninput="calculateInvoice(this)" /></td>
|
||||
name="rate[]" oninput="calculateInvoice(this)" value="<?= isset($ii_details['unit_price']) ? $ii_details['unit_price'] : '' ?>" /></td>
|
||||
<td style="width:5%;"><input type="text" class="form-control item-tax"
|
||||
id="tax" name="tax[]" /></td>
|
||||
id="tax" name="tax[]" value="<?= isset($ii_details['tax']) ? $ii_details['tax'] : '' ?>" /></td>
|
||||
<td style="width:12%;"><input type="text" class="form-control item-amount"
|
||||
id="amount" name="amount[]" /></td>
|
||||
id="amount" name="amount[]" value="<?= isset($ii_details['subtotal']) ? $ii_details['subtotal'] : '' ?>" /></td>
|
||||
<td style="width:12%;"><input type="text"
|
||||
class="form-control item-discount-amount" name="discount_amount[]"
|
||||
oninput="calculateInvoice(this)" />
|
||||
oninput="calculateInvoice(this)" value="<?= isset($ii_details['discount_amount']) ? $ii_details['discount_amount'] : '' ?>" />
|
||||
|
||||
</td>
|
||||
<td style="width:10%;">
|
||||
<select class="form-control item-discount-type" name="discount_type[]"
|
||||
oninput="calculateInvoice(this)">
|
||||
<option value="₹">₹</option>
|
||||
<option value="%">%</option>
|
||||
<option value="₹" <?php if (isset($ii_details['discount_type']) && $ii_details['discount_type'] === '₹') echo "selected"; ?>>₹</option>
|
||||
<option value="%" <?php if (isset($ii_details['discount_type']) && $ii_details['discount_type'] === '%') echo "selected"; ?>>%</option>
|
||||
</select>
|
||||
|
||||
</td>
|
||||
<td><input type="hidden" class="form-control" id="hiddenInvoiceChildId"
|
||||
name="invoice_child_id[]" value=""
|
||||
placeholder="hidden for invoice child/item id" />
|
||||
placeholder="hidden for invoice child/item id" value="<?= isset($ii_details['invoice_child_id']) ? $ii_details['invoice_child_id'] : '' ?>" />
|
||||
<center><i class="fa fa-trash remove-item "></i></center>
|
||||
</td>
|
||||
</tr>
|
||||
@ -286,19 +286,13 @@ document.getElementById("addItem").addEventListener("click", function() {
|
||||
});
|
||||
cell1.appendChild(select);
|
||||
// cell1.innerHTML = '<input type="text" class="form-control" name="item_details[]">';
|
||||
cell2.innerHTML =
|
||||
'<input type="number" class="form-control" id="quantity" name="quantity[]" oninput="calculateInvoice(this)">';
|
||||
cell3.innerHTML =
|
||||
'<input type="text" class="form-control" id="rate" name="rate[]" oninput="calculateInvoice(this)">';
|
||||
cell2.innerHTML = '<input type="number" class="form-control" id="quantity" name="quantity[]" oninput="calculateInvoice(this)">';
|
||||
cell3.innerHTML = '<input type="text" class="form-control" id="rate" name="rate[]" oninput="calculateInvoice(this)">';
|
||||
cell4.innerHTML = '<input type="text" class="form-control item-tax" id="tax" name="tax[]">';
|
||||
cell5.innerHTML = '<input type="text" class="form-control item-amount" id="amount" name="amount[]">';
|
||||
cell6.innerHTML = '<input type="text" class="form-control item-discount-amount" name="discount_amount[]">';
|
||||
cell7.innerHTML =
|
||||
'<select class="form-control item-discount-type" name="discount_type[]" oninput="calculateInvoice(this)"><option value="₹">₹</option><option value="%">%</option></select>';
|
||||
|
||||
cell8.innerHTML =
|
||||
'<input type="hidden" class="form-control" id="hiddenInvoiceChildId" placeholder="hidden for invoice child/item id" name="invoice_child_id[]" value=""><center><i class="fa fa-trash remove-item "></center>';
|
||||
|
||||
cell7.innerHTML = '<select class="form-control item-discount-type" name="discount_type[]" oninput="calculateInvoice(this)"><option value="₹">₹</option><option value="%">%</option></select>';
|
||||
cell8.innerHTML = '<input type="hidden" class="form-control" id="hiddenInvoiceChildId" placeholder="hidden for invoice child/item id" name="invoice_child_id[]" value=""><center><i class="fa fa-trash remove-item "></center>';
|
||||
|
||||
// Attach the calculateInvoice function to new input fields' change events
|
||||
// cell1.getElementsByTagName("input")[0].addEventListener("change", calculateInvoice);
|
||||
@ -539,8 +533,8 @@ document.querySelector("#itemTable tbody").addEventListener("click", function(ev
|
||||
<script>
|
||||
$(document).ready(function() {
|
||||
var iid_arr = <?php echo json_encode($invoice_item_details); ?>;
|
||||
console.log(iid_arr);
|
||||
var cust_id = "<?= isset($invoice_details['customer_id']) ? $invoice_details['customer_id'] : ""; ?>";
|
||||
var ship_addr = "<?= isset($invoice_details['shipping_address']) ? $invoice_details['shipping_address'] : ""; ?>";
|
||||
var ship_addr_id =
|
||||
"<?= isset($invoice_details['shipping_address_id']) ? $invoice_details['shipping_address_id'] : ""; ?>";
|
||||
var bill_addr =
|
||||
@ -619,7 +613,11 @@ $(document).ready(function() {
|
||||
$('#hiddenBillingAddressId').val(customer_billing_id);
|
||||
if (cs.length > 0) {
|
||||
$('#loadShippingDropdown').empty();
|
||||
$('#storeShippingAddress').val('');
|
||||
if (ship_addr != '') {
|
||||
$("#storeShippingAddress").val(ship_addr);
|
||||
}else{
|
||||
$('#storeShippingAddress').val('');
|
||||
}
|
||||
$('#loadShippingDropdown').append($('<option>', {
|
||||
value: "",
|
||||
text: "Select an address"
|
||||
|
||||
@ -7,6 +7,24 @@
|
||||
</div><!-- end col-->
|
||||
<br>
|
||||
<h4 class="header-title mb-3"><?= $page_name; ?></h4>
|
||||
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
|
||||
<?php if (session()->getFlashdata('success')) : ?>
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<?= session('success') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (session()->getFlashdata('error')) : ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<?= session('error') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<div class="table-responsive">
|
||||
<table id="scroll-horizontal-datatable" class="table w-100 nowrap">
|
||||
<thead class="thead-light">
|
||||
|
||||
@ -35,7 +35,32 @@
|
||||
<div class="card-body">
|
||||
<h4 class="header-title"><?= $page_name; ?></h4>
|
||||
</br>
|
||||
<?php if (session()->getFlashdata('success') || session()->getFlashdata('error')) : ?>
|
||||
<?php if (session()->getFlashdata('success')) : ?>
|
||||
<div class="alert alert-success alert-dismissible fade show" role="alert">
|
||||
<?= session('success') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php if (session()->getFlashdata('error')) : ?>
|
||||
<div class="alert alert-danger alert-dismissible fade show" role="alert">
|
||||
<?= session('error') ?>
|
||||
<button type="button" class="close" data-dismiss="alert" aria-label="Close">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
<div id="textDiv">
|
||||
<span class="widget-simple text-center">
|
||||
<div class="media-body align-self-center font-24 avatar-title">
|
||||
<p style="color: #0a0a0a!important;" class="mt-0" style><?= "Please Choose Your Choice....."; ?></p>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
<!-- <div id="textDiv">
|
||||
<span class="widget-simple text-center">
|
||||
<div class="media-body align-self-center font-24 avatar-title">
|
||||
<?php if (isset($validationErrors)) { ?>
|
||||
@ -56,7 +81,7 @@
|
||||
<p style="color: #0a0a0a!important;" class="mt-0" style><?= "Please Choose Your Choice....."; ?></p>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
</div> -->
|
||||
<div id="mailFormDiv">
|
||||
<form role="form" class="parsley-examples" method="POST" enctype="multipart/form-data" action="<?= base_url() . "mail_custom_notifications"; ?>">
|
||||
<div class="form-group row">
|
||||
|
||||
Loading…
Reference in New Issue
Block a user