invoice,subscription

This commit is contained in:
heama 2023-09-27 18:12:52 +05:30
parent f13aaf2bdb
commit 203e7bd042
12 changed files with 468 additions and 37 deletions

View File

@ -86,6 +86,9 @@ $routes->get("delete_scheme/(:any)", "Scheme::delete_scheme/$1");
$routes->get("subscribers_list/", "Subscription::index");
$routes->get("new_subscription/", "Subscription::new_subscription/");
$routes->post("add_subscription/", "Subscription::add_subscription/");
$routes->get('subscription/generate_pdf', 'Subscription::generate_pdf');
#adres priknt
$routes->get('addressprint/', 'Address::index');
$routes->post('address/generatePdf', 'Address::generatePdf');
@ -102,6 +105,8 @@ $routes->post("save_invoice/", "Invoice::save_invoice/");
$routes->get("delete_invoice/(:any)", "Invoice::delete_invoice/$1");
$routes->add('approve_invoice/(:num)', 'Invoice::approve_invoice/$1');
$routes->get('generate_invoice_pdf/(:num)', 'Invoice::generate_invoice_pdf/$1');
$routes->get('print_address/(:num)', 'Invoice::print_address/$1');

View File

@ -23,6 +23,7 @@ class Home extends BaseController
$data['customer'] = $model->customers($where);
$data['customer']['label'] = "Customer";
$this->render_page('dashboard', $data);
}
}

View File

@ -91,18 +91,7 @@ class Invoice extends BaseController
helper('session');
$model = new InvoiceModel();
if ($this->request->getPost('save_as_draft')) {
$status = 'Draft';
} elseif ($this->request->getPost('save_as_approved')) {
$status = 'Approved';
} else {
// Handle other cases or set a default status
$status = 'Draft'; // Default to Draft if no button clicked
}
// ... Other data retrieval and processing ...
$data['status'] = $status;
// 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... )
@ -126,7 +115,7 @@ class Invoice extends BaseController
'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' => $status,
'status' => $this->request->getPost('status'),
'isactive'=> 1];
$invoice_id = $this->request->getPost('invoice_id');
@ -252,14 +241,15 @@ class Invoice extends BaseController
}
public function approve_invoice($id)
{
// Validate $invoice_id (e.g., check if it's a valid 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);
// Return a response (e.g., success message)
return $this->response->setJSON(['message' => 'Invoice approved successfully']);
// Redirect back to the invoice list
return redirect()->route('invoice_list');
}
@ -282,16 +272,54 @@ public function generate_invoice_pdf($id)
$mpdf->SetCreator('');
// Generate the PDF content (HTML)
$html = view('invoice_pdf_template', ['data' => $data,'invoiceItems' => $invoiceItems]);
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)
// {

View File

@ -6,7 +6,7 @@ namespace App\Controllers;
use App\Models\CustomerModel;
use App\Models\SubscriptionModel;
use App\Models\SchemeModel;
use Mpdf\Mpdf;
class Subscription extends BaseController
{ public function index()
@ -73,7 +73,55 @@ public function add_subscription() {
return redirect()->to('subscribers_list')->with('data', $data);
}
}
// Subscription.php (Controller)
public function generate_pdf()
{
$schemeName = $this->request->getGet('scheme_name');
// Call the model method to get customer addresses
$subscriptionModel = new SubscriptionModel();
$addresses = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName);
$billingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 1);
$shippingInfo = $subscriptionModel->getCustomerAddressesBySchemeName($schemeName, 2);
$customerName = $subscriptionModel->getCustomerNameBySchemeName($schemeName);
// Create an HTML content string using the view file
if ($customerName !== 'Customer not found') {
// Create an HTML content string using the view file
$html = view('print_addresses_form', ['customerName' => $customerName, 'billingInfo' => $billingInfo, 'shippingInfo' => $shippingInfo]);
// Generate a PDF from the HTML content
$pdf = new Mpdf();
$pdf->WriteHTML($html);
// Output the PDF to the browser in a new tab
$pdf->Output('CustomerAddress.pdf', 'D');
} else {
// Handle the case where the customer is not found
echo 'Customer not found';
}
}
}
// 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)
// }

View File

@ -8,7 +8,7 @@ class InvoiceModel extends Model
protected $table = 'invoice';
protected $primaryKey = 'invoice_id';
// protected $allowedFields = ['invoice_id','invoice_number','customer_id','invoice_date','event_id','business_id','created_on','business_id'];
protected $allowedFields = ['invoice_id', 'invoice_number', 'customer_id', 'invoice_date', 'due_date', 'subtotal', 'tax', 'discount', 'total_amount', 'payment_status', 'order_number', 'payment_method', 'event_id', 'business_id', 'shipping_address_id', 'billing_address_id', 'created_on', 'created_by', 'updated_on', 'updated_by', 'isactive','billing_address','shipping_address'];
protected $allowedFields = ['invoice_id', 'invoice_number', 'customer_id', 'invoice_date', 'due_date', 'subtotal', 'tax', 'discount', 'total_amount', 'payment_status', 'order_number', 'payment_method', 'event_id', 'business_id', 'shipping_address_id', 'billing_address_id', 'created_on', 'created_by', 'updated_on', 'updated_by', 'isactive','billing_address','shipping_address','status'];
public function saveInvoiceItemDetails($data){
$i = 0;
@ -99,9 +99,12 @@ public function updateData($table, $data, $where)
->where('invoice_id', $id)
->join('customers as C','C.customer_id= invoice.customer_id','left')
->join('business as B','B.business_id = invoice.business_id','left')
->select('invoice.*,concat(C.first_name," ",C.last_name) as customer_name,B.title,B.business_logo,B.address,B.city,B.state,B.postal_code,B.email,B.mobile_no')
->join('customer_addresses as A','A.customer_id=invoice.customer_id and A.address_type=1','left')
->select('invoice.*,concat(C.first_name," ",C.last_name) as customer_name,A.address_1, A.address_2,A.postal_code,A.city, A.state,C.mobile_no,B.title,B.business_logo,B.address,B.city,B.state,B.postal_code,B.email,B.mobile_no')
->get()
->getResult();
}
public function getInvoiceItems($id)
{

View File

@ -36,6 +36,7 @@ class SchemeModel extends Model
return $schemes;
}
// public function getSchemeDuration($schemeId)
// {
// $query = $this->select('duration')
@ -49,6 +50,39 @@ class SchemeModel extends Model
// return null;
// }
// }
public function getSchemeNamesByBusiness($business_id)
{
$builder = $this->builder();
$builder->select('scheme_id, scheme_name');
$builder->where('business_id', $business_id);
$query = $builder->get();
$schemes = [];
foreach ($query->getResult() as $row) {
$schemes[$row->scheme_id] = $row->scheme_name;
}
return $schemes;
}
public function getSchemeNames()
{
$builder = $this->builder();
$builder->select('scheme_id, scheme_name');
$query = $builder->get();
$schemes =[];
foreach ($query->getResult() as $row) {
$schemes[$row->scheme_id] = $row->scheme_name;
}
return $schemes;
print_r($schemes);die();
}
}

View File

@ -21,5 +21,73 @@ public function getAllSubscribersWithNames($where)
$builder->where($where);
return $builder->get()->getResultArray();
}
public function getCustomerNameBySchemeName($schemeName)
{
$builder = $this->db->table('subscription');
$builder->select('customers.first_name, customers.last_name');
$builder->select('customer_addresses.address_1, customer_addresses.address_2');
$builder->join('customer_addresses', 'customer_addresses.customer_id = subscription.customer_id');
$builder->join('customers', 'customers.customer_id = subscription.customer_id');
$builder->join('schemes', 'schemes.scheme_id = subscription.scheme_id');
$builder->where('schemes.scheme_name', $schemeName);
$query = $builder->get();
if ($query->getNumRows() > 0) {
$row = $query->getRow();
return $row->first_name . ' ' . $row->last_name;
} else {
return 'Customer not found'; // You can return a default value or handle the case where the customer is not found.
}
}
public function getCustomerAddressesBySchemeName($schemeName)
{
$builder = $this->db->table('subscription');
$builder->select('CONCAT(customers.first_name, " ", customers.last_name) as customer_name, customer_addresses.address_1, customer_addresses.address_2, customer_addresses.city, customer_addresses.state,customer_addresses.postal_code, customer_addresses.address_type,business.address,business.city,business.state,business.postal_code,business.country');
$builder->join('customers', 'customers.customer_id = subscription.customer_id');
$builder->join('customer_addresses', 'customer_addresses.customer_id = subscription.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);
$query = $builder->get();
$addresses = [];
if ($query->getNumRows() > 0) {
foreach ($query->getResult() as $row) {
$addressType = $row->address_type;
$addresses[$addressType] = [
'customer_name' => $row->customer_name,
'address_1' => $row->address_1,
'address_2' =>$row->address_2,
'city' => $row->city,
'state' => $row->state,
'postal_code'=>$row->postal_code,
];
}
} else {
$addresses = [
'billing' => [
'customer_name' => 'Customer not found',
'address_line' => 'Billing Address not found',
'city' => '',
'state' => '',
],
'shipping' => [
'customer_name' => 'Customer not found',
'address_line' => 'Shipping Address not found',
'city' => '',
'state' => '',
],
];
}
return $addresses;
}
}

View File

@ -0,0 +1,80 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shipping Label Template</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.shipping-label {
width: 250px; /* Reduced width for courier cover */
margin: 20px auto;
border: 1px solid #000;
background-color: #fff;
padding: 10px;
}
.label-title {
font-size: 14px; /* Reduced font size for title */
font-weight: bold;
margin-bottom: 10px;
}
.address {
font-size: 12px; /* Reduced font size for address */
margin-top: 10px;
}
.barcode {
text-align: center;
margin-top: 20px;
}
.barcode img {
max-width: 100%;
}
.footer {
font-size: 10px;
text-align: center;
margin-top: 10px;
}
.business-logo {
max-width: 150px; /* Adjust the logo size */
}
</style>
</head>
<body>
<div class="shipping-label">
<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">
</div>
<?php foreach ($invoiceData as $value) : ?>
<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 class="address">
<p>To:</p>
<p><?= $value->customer_name ?></p>
<p><?= $value->address_1 ?><?= $value->address_2 ?></p>
<p><?= $value->city ?>&nbsp;<?= $value->state ?></p>
<p><?= $value->postal_code ?></p>
</div>
<div class="barcode">
<img src="barcode.png" alt="Barcode">
</div>
<div class="footer">Thank you for choosing our service</div>
</div>
<?php endforeach; ?>
</body>
</html>

View File

@ -228,16 +228,20 @@
</div>
</div>
</div>
<input type="hidden" id="hiddenInvoiceId" name="invoice_id" placeholder="hidden for invoice id"
value="<?= isset($invoice_details['invoice_id']) ? $invoice_details['invoice_id'] : '' ?>" />
<div class="form-group text-right m-b-0">
<button type="submit" name="save_as_draft">Save as Draft</button>
<button type="submit" name="save_as_approved">Save as Approved</button>
</button>
</button>
<button type="reset" class="btn btn-primary waves-effect mr-1">
Reset
</button>
<?php if (isset($invoice_details['status']) && $invoice_details['status'] !== 'Approved'): ?>
<!-- Show the "Save as Draft" button only if the status is not "Approved" -->
<button type="submit" class="btn btn-primary waves-effect mr-1" name="save_as_draft" id="saveDraftButton">Save as Draft</button>
<?php endif; ?>
<?php if (!isset($invoice_details['status']) || $invoice_details['status'] !== 'Approved'): ?>
<!-- Show the "Save as Approved" button only if the status is not "Approved" -->
<button type="submit" class="btn btn-primary waves-effect mr-1" name="save_as_approved" id="saveApprovedButton">Save as Approved</button>
<?php endif; ?>
<input type="hidden" id="status" name="status" value="">
</div>
</form>
</div>
@ -683,4 +687,15 @@ $(document).ready(function() {
}
});
</script>
</script>
<script>
document.getElementById('saveDraftButton').addEventListener('click', function () {
// Set the status field to 'Draft' before submitting
document.getElementById('status').value = 'Draft';
});
document.getElementById('saveApprovedButton').addEventListener('click', function () {
// Set the status field to 'Approved' before submitting
document.getElementById('status').value = 'Approved';
});
</script>

View File

@ -20,8 +20,10 @@
<th>Discount</th>
<th>Tax</th> -->
<th>Status</th>
<th>Approve INV</th>
<th>Action</th>
<th>view</th>
<th>Print</th>
</tr>
</thead>
<tbody>
@ -31,16 +33,20 @@
<td><?php echo $row->invoice_number;?></td>
<td><?php echo $row->invoice_date;?></td>
<td><?php echo $row->customer_name;?></td>
<td><?php echo $row->status;?>
<a href="<?= "approve_invoice/" . $row->invoice_id; ?>" class="approve-button"><i class="ri-checkbox-circle-fill"></i> Approve</a>
<td><?php echo $row->status;?></td>
<td style align="center"><a href="<?= "approve_invoice/" . $row->invoice_id; ?>" class="approve-button"><i class="ri-checkbox-circle-fill"></i></a>
</td>
<td>
<a href="<?= "new_invoice/" . $row->invoice_id; ?>" class="edit-button"><i class="ri-pencil-line"></i></a>
</td>
<td>
<a href="<?= base_url("generate_invoice_pdf/{$row->invoice_id}") ?>" class="download-pdf-button"><i class="ri-file-pdf-fill"></i> Download PDF</a>
<a href="<?= base_url("generate_invoice_pdf/{$row->invoice_id}") ?>" class="download-pdf-button"><i class="ri-file-download-line"></i></a>
</td>
<td>
<a href="<?= base_url("print_address/{$row->invoice_id}") ?>" class="print-address-button"><i class="ri-printer-line"></i></a>
</td>

View File

@ -0,0 +1,80 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Shipping Label Template</title>
<style>
body {
font-family: Arial, sans-serif;
margin: 0;
padding: 0;
}
.shipping-label {
width: 250px; /* Reduced width for courier cover */
margin: 20px auto;
border: 1px solid #000;
background-color: #fff;
padding: 10px;
}
.label-title {
font-size: 14px; /* Reduced font size for title */
font-weight: bold;
margin-bottom: 10px;
}
.address {
font-size: 12px; /* Reduced font size for address */
margin-top: 10px;
}
.barcode {
text-align: center;
margin-top: 20px;
}
.barcode img {
max-width: 100%;
}
.footer {
font-size: 10px;
text-align: center;
margin-top: 10px;
}
.business-logo {
max-width: 150px; /* Adjust the logo size */
}
</style>
</head>
<body>
<div class="shipping-label">
<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">
</div>
<div class="address">
<?php foreach ($addresses as $value) : ?>
<p><?= $value['postal_code'] ?></p>
</div>
<?php endforeach; ?>
<div class="address">
<p>To:</p>
<p><?= $customerName?></p>
<?php foreach ($shippingInfo as $row) : ?>
<p><?= $row['address_1'] ?><?= $row['address_2'] ?></p>
<p><?= $row['city'] ?>&nbsp;<?= $row['state'] ?></p>
<p><?= $row['postal_code'] ?></p>
</div>
<div class="barcode">
<img src="barcode.png" alt="Barcode">
</div>
<div class="footer">Thank you for choosing our service</div>
</div>
<?php endforeach; ?>
</body>
</html>

View File

@ -3,7 +3,11 @@
<div class="card">
<div class="card-body">
<div class="float-right">
<a href="#" class="btn btn-secondary" id="openSchemeListModal"><i class="ri-printer-line"></i> Print Address</a>
<a href="new_subscription" class="btn btn-primary"><i class="ri-shield-user-line"></i> Add New </a>
</div><!-- end col-->
<br>
<h4 class="header-title mb-3"><?= $page_name; ?></h4>
@ -35,8 +39,67 @@
<?php endforeach; ?>
</tbody>
</table>
</div>
<!-- Address Print Popup (Modal) -->
<!-- Scheme List Modal -->
<!-- Scheme List Modal -->
<div class="modal fade" id="schemeListModal" tabindex="-1" role="dialog" aria-labelledby="schemeListModalLabel" aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="schemeListModalLabel">Select Schemes</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">&times;</span>
</button>
</div>
<div class="modal-body">
<ul>
<?php foreach ($subscriber as $scheme) : ?>
<li>
<label>
<input type="checkbox" class="scheme-checkbox" value="<?= $scheme['scheme_name']; ?>">
<?= $scheme['scheme_name']; ?>
</label>
</li>
<?php endforeach; ?>
</ul>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-primary" id="printAddress">Print Address</button>
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
</div>
</div>
</div>
</div>
</div>
</div> <!-- end card body-->
</div> <!-- end card -->
</div><!-- end col-->
</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>