subscription module

This commit is contained in:
heama 2023-09-28 17:04:11 +05:30
parent 2c8f40a69e
commit 048d9ba61b
7 changed files with 201 additions and 97 deletions

View File

@ -86,7 +86,8 @@ $routes->get("delete_scheme/(:any)", "Scheme::delete_scheme/$1");
$routes->get("subscribers_list/", "Subscription::index"); $routes->get("subscribers_list/", "Subscription::index");
$routes->get("new_subscription/", "Subscription::new_subscription/"); $routes->get("new_subscription/", "Subscription::new_subscription/");
$routes->post("add_subscription/", "Subscription::add_subscription/"); $routes->post("add_subscription/", "Subscription::add_subscription/");
$routes->get('subscription/generate_pdf', 'Subscription::generate_pdf'); $routes->post('subscription/download_details', 'Subscription::download_details');
#adres priknt #adres priknt

View File

@ -75,34 +75,64 @@ public function add_subscription() {
// Subscription.php (Controller) // Subscription.php (Controller)
public function generate_pdf() // 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()
{ {
$schemeName = $this->request->getGet('scheme_name'); $selectedScheme = $this->request->getPost('selected_scheme');
// Call the model method to get customer addresses // Call the model method to get all customer details for the selected scheme
$subscriptionModel = new SubscriptionModel(); $subscriptionModel = new SubscriptionModel();
$addresses = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName); $customerDetails = $subscriptionModel->getAllCustomerDetailsBySchemeName($selectedScheme);
$billingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 1);
$shippingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 2);
$customerName = $subscriptionModel->getCustomerNameBySchemeName($schemeName);
// Create an HTML content string using the view file // Create an HTML content string using the view file (similar to print_addresses.php)
if ($customerName !== 'Customer not found') { if (!empty($customerDetails)) {
// Create an HTML content string using the view file $html = view('print_addresses_form', ['customerDetails' => $customerDetails]);
$html = view('print_addresses_form', ['customerName' => $customerName, 'billingInfo' => $billingInfo, 'shippingInfo' => $shippingInfo]);
// Generate a PDF from the HTML content // Generate a PDF from the HTML content
$pdf = new Mpdf(); $pdf = new Mpdf();
$pdf->WriteHTML($html); $pdf->WriteHTML($html);
// Output the PDF to the browser in a new tab // Set the PDF filename
$pdf->Output('CustomerAddress.pdf', 'D'); $filename = 'CustomerDetails_' . date('YmdHis') . '.pdf';
// Output the PDF for download
$pdf->Output($filename, 'D');
} else { } else {
// Handle the case where the customer is not found // Handle the case where no customer details are found for the selected scheme
echo 'Customer not found'; echo 'No customer details found for the selected scheme.';
} }
} }
} }
// public function generate_pdf() // public function generate_pdf()
// { // {

View File

@ -81,10 +81,28 @@ public function getSchemeNames()
print_r($schemes);die(); print_r($schemes);die();
} }
public function getSchemeNameById($schemeId)
{
// Query the database to retrieve the scheme name by ID
$builder = $this->db->table('schemes');
$builder->select('scheme_name');
$builder->where('scheme_id', $schemeId);
$query = $builder->get();
// Check if a record was found
if ($query->getNumRows() > 0) {
$row = $query->getRow();
return $row->scheme_name;
} else {
return null; // Return null if no scheme with the given ID is found
}
}
public function getAllSchemes()
{
return $this->findAll();
}
} }

View File

@ -86,8 +86,69 @@ public function getCustomerAddressesBySchemeName($schemeName)
return $addresses; return $addresses;
} }
public function getAllCustomerDetailsBySchemeName($schemeName)
{
$builder = $this->db->table('subscription');
$builder->select('customers.customer_id, CONCAT(customers.first_name, " ", customers.last_name) as customer_name,customer_addresses.mobile_no, customer_addresses.address_1,customer_addresses.address_2, customer_addresses.city, customer_addresses.state, customer_addresses.postal_code,business.title,business.address,business.city,business.state,business.postal_code,schemes.scheme_name,from_subscription,to_subscription');
$builder->join('customers', 'customers.customer_id = subscription.customer_id');
$builder->join('customer_addresses', 'customer_addresses.customer_id = customers.customer_id');
$builder->join('business', 'business.business_id = subscription.business_id');
$builder->join('schemes', 'schemes.scheme_id = subscription.scheme_id');
$builder->where('schemes.scheme_name', $schemeName);
$builder->where('customer_addresses.address_type', 2); // Filter by address_type 2
$builder->orderBy('customers.customer_id', 'ASC'); // Order by customer_id to group by customers
// Fetch the query result
$query = $builder->get();
$customerDetails = [];
if ($query->getNumRows() > 0) {
$currentCustomerID = null;
$shippingAddress = [];
foreach ($query->getResultArray() as $row) {
$customerID = $row['customer_id'];
if ($currentCustomerID !== $customerID) {
// New customer, add the previous customer's details (if any)
if (!empty($shippingAddress)) {
$customerDetails[] = $shippingAddress;
}
// Start a new customer's details
$shippingAddress = [
'customer_name' => $row['customer_name'],
'address_1' => $row['address_1'],
'address_2' => $row['address_2'],
'mobile_no'=>$row['mobile_no'],
'city' => $row['city'],
'state' => $row['state'],
'postal_code' => $row['postal_code'],
'address' => $row['address'],
'city' => $row['city'],
'state' => $row['state'],
'postal_code' => $row['postal_code'],
'title' => $row['title'],
'to_subscription'=>$row['to_subscription'],
'scheme_name'=>$row['scheme_name'],
];
$currentCustomerID = $customerID;
}
}
// Add the last customer's details (if any)
if (!empty($shippingAddress)) {
$customerDetails[] = $shippingAddress;
}
}
return $customerDetails;
}
} }

View File

@ -12,21 +12,22 @@
} }
.shipping-label { .shipping-label {
width: 250px; /* Reduced width for courier cover */ width: 400px; /* Set the width */
margin: 20px auto; height: 140px; /* Set the height to match the width for a square shape */
margin: 10px;
border: 1px solid #000; border: 1px solid #000;
background-color: #fff; background-color: #fff;
padding: 10px; padding: 10px;
} }
.label-title { .label-title {
font-size: 14px; /* Reduced font size for title */ font-size: 12px;
font-weight: bold; font-weight: bold;
margin-bottom: 10px; margin-bottom: 10px;
} }
.address { .address {
font-size: 12px; /* Reduced font size for address */ font-size: 16px;
margin-top: 10px; margin-top: 10px;
} }
@ -40,29 +41,26 @@
} }
.footer { .footer {
font-size: 10px; font-size: 14px;
text-align: center; text-align: center;
margin-top: 10px; margin-top: 10px;
} }
.business-logo { .business-logo {
max-width: 150px; /* Adjust the logo size */ max-width: 150px;
} }
</style> </style>
</head> </head>
<body> <body>
<?php foreach ($invoiceData as $value) : ?>
<div class="shipping-label"> <div class="shipping-label">
<div class="label-title"> <div class="label-title">
<img src="https://vijayabharathambooks.com/wp-content/uploads/2021/09/vijaya-bharatham-logo-8pt.png" alt="Business Logo" class="business-logo"> <img src="https://vijayabharathambooks.com/wp-content/uploads/2021/09/vijaya-bharatham-logo-8pt.png" alt="Business Logo" class="business-logo"><br>
</div> <?= $value->address ?>,<br><?= $value->city ?>, <?= $value->state ?>,
<?php foreach ($invoiceData as $value) : ?> <?= $value->postal_code ?>
<div class="address">
<p><?= $value->address ?>,<br><?= $value->city ?>, <?= $value->state ?>,</p>
<p><?= $value->postal_code ?></p>
<p><?= $value->email ?></p>
<p><?= $value->mobile_no ?></p>
</div> </div>
<div class="address"> <div class="address">
<p>To:</p> <p>To:</p>
<p><?= $value->customer_name ?></p> <p><?= $value->customer_name ?></p>

View File

@ -12,21 +12,22 @@
} }
.shipping-label { .shipping-label {
width: 250px; /* Reduced width for courier cover */ width: 600px; /* Set the width */
margin: 20px auto; height: 140px; /* Set the height to match the width for a square shape */
margin: 10px;
border: 1px solid #000; border: 1px solid #000;
background-color: #fff; background-color: #fff;
padding: 10px; padding: 10px;
} }
.label-title { .label-title {
font-size: 14px; /* Reduced font size for title */ font-size: 10px;
font-weight: bold; font-weight: bold;
margin-bottom: 10px; margin-bottom: 10px;
} }
.address { .address {
font-size: 12px; /* Reduced font size for address */ font-size: 16px;
margin-top: 10px; margin-top: 10px;
} }
@ -40,40 +41,48 @@
} }
.footer { .footer {
font-size: 10px; font-size: 14px;
text-align: center; text-align: center;
margin-top: 10px; margin-top: 10px;
} }
.business-logo { .business-logo {
max-width: 150px; /* Adjust the logo size */ max-width: 150px;
} }
</style> </style>
</head> </head>
<body> <body>
<?php foreach ($customerDetails as $customer) : ?>
<div class="shipping-label"> <div class="shipping-label">
<div class="label-title"> <div class="label-title">
<img src="https://vijayabharathambooks.com/wp-content/uploads/2021/09/vijaya-bharatham-logo-8pt.png" alt="Business Logo" class="business-logo"> <img src="https://vijayabharathambooks.com/wp-content/uploads/2021/09/vijaya-bharatham-logo-8pt.png" alt="Business Logo" class="business-logo"><br>
&nbsp;
<?= $customer['address'] ?>
<?= $customer['city'] ?>- <?= $customer['postal_code'] ?>
</div> </div>
<div class="address">
<?php foreach ($addresses as $value) : ?>
<p><?= $value['postal_code'] ?></p>
</div>
<?php endforeach; ?>
<div class="address"> <div class="address">
<p>To:</p> <p>To:</p>
<p><?= $customerName?></p> <?= $customer['customer_name'] ?><br>
<?php foreach ($shippingInfo as $row) : ?> <?= $customer['address_1'] ?>
<p><?= $row['address_1'] ?><?= $row['address_2'] ?></p> <?= $customer['address_2'] ?><br>
<p><?= $row['city'] ?>&nbsp;<?= $row['state'] ?></p> <?= $customer['postal_code'] ?><br>
<p><?= $row['postal_code'] ?></p> <?= $customer['city'] ?><br>
<?= $customer['state'] ?>&nbsp;&nbsp;&nbsp;<br>
<?= $customer['mobile_no'] ?></p>
</div> </div>
<div class="barcode"> <div class="barcode">
<img src="barcode.png" alt="Barcode"> <img src="barcode.png" alt="Barcode">
</div> </div>
<div class="footer">Thank you for choosing our service</div>
<div class="footer">"<?= $customer['scheme_name'] ?>" Expires on "<?= $customer['to_subscription'] ?>" </div>
</div> </div>
<?php endforeach; ?> <?php endforeach; ?>
</body> </body>

View File

@ -3,8 +3,8 @@
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<div class="float-right"> <div class="float-right">
<!-- Add a "Print Addresses" button -->
<a href="#" class="btn btn-secondary" id="openSchemeListModal"><i class="ri-printer-line"></i> Print Address</a> <button type="button" class="btn btn-primary" data-toggle="modal" data-target="#printAddressesModal">Print Addresses</button>
<a href="new_subscription" class="btn btn-primary"><i class="ri-shield-user-line"></i> Add New </a> <a href="new_subscription" class="btn btn-primary"><i class="ri-shield-user-line"></i> Add New </a>
@ -44,34 +44,41 @@
<!-- Scheme List Modal --> <!-- Scheme List Modal -->
<div class="modal fade" id="schemeListModal" tabindex="-1" role="dialog" aria-labelledby="schemeListModalLabel" aria-hidden="true"> <!-- Create a modal for scheme selection -->
<div class="modal-dialog modal-dialog-centered" role="document"> <!-- Create a modal for scheme selection -->
<div class="modal fade" id="printAddressesModal" tabindex="-1" role="dialog" aria-labelledby="printAddressesModalLabel" aria-hidden="true">
<div class="modal-dialog" role="document">
<div class="modal-content"> <div class="modal-content">
<div class="modal-header"> <div class="modal-header">
<h5 class="modal-title" id="schemeListModalLabel">Select Schemes</h5> <h5 class="modal-title" id="printAddressesModalLabel">Select Schemes to Print Addresses</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close"> <button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span> <span aria-hidden="true">&times;</span>
</button> </button>
</div> </div>
<div class="modal-body"> <div class="modal-body">
<ul> <!-- Create a form to select schemes and download details -->
<?php foreach ($subscriber as $scheme) : ?> <!-- ... Inside the modal in subscriber_list.php ... -->
<li> <form action="<?= base_url('subscription/download_details'); ?>" method="post">
<label> <div class="form-group">
<input type="checkbox" class="scheme-checkbox" value="<?= $scheme['scheme_name']; ?>"> <?php
<?= $scheme['scheme_name']; ?> $uniqueSchemes = []; // Array to track unique scheme names
</label> foreach ($subscriber as $scheme) :
</li> // Check if the scheme name is already in the unique list
<?php endforeach; ?> if (!in_array($scheme['scheme_name'], $uniqueSchemes)) {
</ul> $uniqueSchemes[] = $scheme['scheme_name']; // Add to unique list
</div> ?>
<div class="modal-footer"> <div class="form-check">
<button type="button" class="btn btn-primary" id="printAddress">Print Address</button> <input class="form-check-input" type="radio" name="selected_scheme" value="<?= $scheme['scheme_name']; ?>">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button> <label class="form-check-label"><?= $scheme['scheme_name']; ?></label>
</div>
</div>
</div> </div>
<?php
}
endforeach;
?>
</div> </div>
<button type="submit" class="btn btn-primary">Download Details</button>
</form>
@ -82,24 +89,4 @@
</div> <!-- end card --> </div> <!-- end card -->
</div><!-- end col--> </div><!-- end col-->
</div> </div>
<script>
$(document).ready(function () {
// Open the Scheme List Modal when "Print Address" button is clicked
$("#openSchemeListModal").click(function () {
$("#schemeListModal").modal("show");
});
// Handle the "Print Address" button click inside the modal
$("#printAddress").click(function () {
const selectedScheme = $(".scheme-checkbox:checked").val();
if (!selectedScheme) {
alert("Please select a scheme.");
return;
}
// Redirect to a URL that generates the PDF with the selected customer name
window.location.href = '<?= base_url('subscription/generate_pdf'); ?>?scheme_name=' + encodeURIComponent(selectedScheme);
});
});
</script>