218 lines
7.7 KiB
PHP
218 lines
7.7 KiB
PHP
<?php
|
|
|
|
namespace App\Controllers;
|
|
|
|
// use App\Models\SubscriptionModel;
|
|
use App\Models\CustomerModel;
|
|
use App\Models\SubscriptionModel;
|
|
use App\Models\SchemeModel;
|
|
use App\Models\InvoiceModel;
|
|
use Mpdf\Mpdf;
|
|
|
|
class Subscription extends BaseController
|
|
{ public function index()
|
|
{
|
|
// echo base_url('public/uploads/vijayabharathampdf.png');die();
|
|
helper('session');
|
|
if (is_session_active()) {
|
|
$session_role = get_user_role();
|
|
$session_bid = get_business_id();
|
|
|
|
if (!empty($session_role) && $session_role !== "sadmin") {
|
|
$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'] = 'Subscription Invoice Details';
|
|
$data['invoice'] = $model->getSubscriptionInvoiceDetail($where);
|
|
|
|
$this->logger->info("Invoice: Listing Count ." . count($data['invoice']));
|
|
|
|
|
|
// $data['subscriber'] = $SubscriptionModel->where($where)->findAll();;
|
|
|
|
|
|
$SubscriptionModel = new SubscriptionModel();
|
|
$swhere = ['subscription.business_id' => (int)$session_bid];
|
|
$data['subscriber'] = $SubscriptionModel->getAllSubscribersWithNames($swhere);
|
|
$this->render_page('subscribers_list', $data);
|
|
}else {
|
|
return redirect()->to('login');
|
|
}
|
|
}
|
|
public function new_subscription() {
|
|
|
|
helper('session');
|
|
helper('session');
|
|
$session_bid = get_business_id();
|
|
$data['page_name'] = 'Subscription Details';
|
|
$customerModel = new CustomerModel();
|
|
$schemeModel = new SchemeModel();
|
|
|
|
$business_id = get_business_id();
|
|
|
|
// Get scheme names and durations from the SchemeModel
|
|
$data['customers'] = $customerModel->getCustomerNamesByBusiness($business_id);
|
|
$data['scheme_names'] = $schemeModel->getSchemeNamesAndDurationsByBusiness($business_id);
|
|
|
|
//print_r($data);die();
|
|
$this->render_page('subscription_form', $data);
|
|
}
|
|
|
|
// Subscription Controller (Subscription.php)
|
|
public function add_subscription() {
|
|
helper('session');
|
|
$session_bid = get_business_id();
|
|
$session_uid = get_logged_user_id();
|
|
|
|
$SubscriptionModel = new SubscriptionModel();
|
|
$data = [
|
|
'scheme_id' =>$this->request->getPost('scheme'),
|
|
'customer_id' =>$this->request->getPost('customer'),
|
|
'from_subscription' => $this->request->getPost('from_date'),
|
|
'to_subscription' => $this->request->getPost('to_date'),
|
|
// 'type' => "subscribed customer",
|
|
'type' => "customer",
|
|
'mode' => $this->request->getPost('mode'),
|
|
'business_id'=>$session_bid
|
|
];
|
|
|
|
$SubscriptionModel->insert($data);
|
|
|
|
// $data['subscriber'] = $subscriberModel->getAllSubscribersWithNames();
|
|
// print_r($data);die();
|
|
return redirect()->to('subscribers_list')->with('data', $data);
|
|
}
|
|
|
|
// Subscription.php (Controller)
|
|
|
|
// public function download_details()
|
|
// {
|
|
// $selectedScheme = $this->request->getPost('selected_scheme');
|
|
|
|
// // Call the model method to get customer details for the selected scheme
|
|
// $subscriptionModel = new SubscriptionModel();
|
|
// $business = $subscriptionModel->getCustomerAddressesBySchemeName($selectedScheme);
|
|
|
|
// $shippingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($selectedScheme, 2);
|
|
// $customerName = $subscriptionModel->getCustomerNameBySchemeName($selectedScheme);
|
|
|
|
// // Create an HTML content string using the view file (similar to print_addresses.php)
|
|
// if ($customerName !== 'Customer not found') {
|
|
// $html = view('print_addresses_form', ['customerName' => $customerName, 'shippingInfo' => $shippingInfo, 'business' => $business]);
|
|
|
|
// // Generate a PDF from the HTML content
|
|
// $pdf = new Mpdf();
|
|
|
|
// $pdf->WriteHTML($html);
|
|
|
|
// // Set the PDF filename
|
|
// $filename = 'CustomerDetails_' . date('YmdHis') . '.pdf';
|
|
|
|
// // Output the PDF for download
|
|
// $pdf->Output($filename, 'D');
|
|
// } else {
|
|
// // Handle the case where the customer is not found
|
|
// echo 'Customer not found';
|
|
// }
|
|
// }
|
|
|
|
public function download_details()
|
|
{
|
|
$selectedSchemes = $this->request->getPost('selected_schemes');
|
|
$action = $this->request->getPost('action');
|
|
// Initialize an empty PDF with custom paper size (4x6 inches)
|
|
$config = [
|
|
'mode' => 'utf-8',
|
|
'format' => [101.6, 152.4],
|
|
'default_font_size' => 12,
|
|
'default_font' => 'Arial',
|
|
'margin_left' => 0,
|
|
'margin_right' => 0,
|
|
'margin_top' => 0,
|
|
'margin_bottom' => 0,
|
|
'margin_header' => 0,
|
|
'margin_footer' => 0,
|
|
'orientation' => 'P', // Portrait
|
|
];
|
|
|
|
$configA4 = [
|
|
'mode' => 'utf-8',
|
|
'format' => [101.6 * 2, 152.4 * 4], // 2x4 inches for each label
|
|
'default_font_size' => 12,
|
|
'default_font' => 'Arial',
|
|
'margin_left' => 0,
|
|
'margin_right' => 0,
|
|
'margin_top' => 0,
|
|
'margin_bottom' => 0,
|
|
'margin_header' => 0,
|
|
'margin_footer' => 0,
|
|
'orientation' => 'P', // Portrait
|
|
];
|
|
|
|
|
|
if($action == 1) $pdf = new Mpdf($config);
|
|
else $pdf = new Mpdf();
|
|
$customerDetails = [];
|
|
// Iterate through selected schemes
|
|
if (!empty($selectedSchemes)) {
|
|
foreach ($selectedSchemes as $selectedScheme) {
|
|
// Call the model method to get customer details for each selected scheme
|
|
$subscriptionModel = new SubscriptionModel();
|
|
$details = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme);
|
|
$customerDetails = array_merge($customerDetails, $details);
|
|
}
|
|
|
|
if (!empty($customerDetails)) {
|
|
$html = view('print_addresses_form', ['customerDetails' => $customerDetails , 'action' => $action , 'pdf' => $pdf]);
|
|
// Add the current scheme's details to the PDF
|
|
// echo $html;die;
|
|
// $pdf->AddPage();
|
|
$pdf->WriteHTML($html);
|
|
// Set the PDF filename
|
|
$filename = 'CustomerDetails_' . date('YmdHis') . '.pdf';
|
|
|
|
// Output the PDF for download
|
|
$pdf->Output($filename, 'D');
|
|
$this->logger->info("Print Addresses (Scheme) : Downloaded = ".$filename);
|
|
} else {
|
|
echo "<script>alert('Customer Details Not Available.');</script>";
|
|
$this->logger->info("Print Addresses (Scheme) : Details Not Available ");
|
|
}
|
|
} else {
|
|
echo "<script>alert('Schemes Not Choosen.');</script>";
|
|
$this->logger->info("Print Addresses (Scheme) : Schemes Not Choosen ");
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
}
|
|
// public function generate_pdf()
|
|
// {
|
|
// $schemeName = $this->request->getGet('scheme_name');
|
|
|
|
// // Call the model method to get the customer's name and address (billing or shipping)
|
|
// $subscriptionModel = new SubscriptionModel();
|
|
|
|
// // For billing address
|
|
// $billingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 1);
|
|
|
|
// // For shipping address
|
|
// $shippingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 2);
|
|
// print_r($billingInfo);
|
|
// print_r($shippingInfo);
|
|
|
|
|
|
// // Handle the PDF generation using $billingInfo['customer_name'], $billingInfo['address'] (for billing address)
|
|
// // and $shippingInfo['customer_name'], $shippingInfo['address'] (for shipping address)
|
|
// }
|
|
|
|
|