Merge branch 'main' of bitbucket.org:venbainformationtechnology/the_mechanic

This commit is contained in:
bitbucket 2024-04-05 15:12:56 +05:30
commit 61daab30b3
5 changed files with 405 additions and 5 deletions

View File

@ -47,6 +47,7 @@ $routes->post("add_sales", "Sales::add_sales");
$routes->get("new_sale/(:any)", "Sales::new_sale/$1");
$routes->get("delete_sale/(:any)", "Sales::delete_sale/$1");
$routes->post("delete_sales_product", "Sales::delete_sales_product");
$routes->get("download_invoice/(:any)", "Sales::download_invoice/$1");
//end salle order//
//Client//

View File

@ -6,9 +6,16 @@ use App\Models\SalesOrderModel;
use App\Models\SalesOrderProductModel;
use App\Models\ProductModel;
use App\Models\ClientModel;
use Mpdf\Mpdf;
class Sales extends BaseController
{
public $session;
public function __construct()
{
$this->session = session();
}
public function sales_order_index()
{
@ -79,7 +86,8 @@ $data['product']=$product;
'discount'=> $this->request->getPost('discount'),
'total'=> $this->request->getPost('grand_total'),
'status'=> $this->request->getPost('status'),
'isactive' => 1 // Assuming this is a default value or handled separately
'isactive' => 1, // Assuming this is a default value or handled separately
'branch_id'=> $this->session->get('logged_user_branch_id'),
];
// print_r($data);die;
// Insert or update sales order
@ -176,5 +184,74 @@ public function delete_sales_product()
return redirect()->to('sales_order_index');
}
public function download_invoice($sales_order_id)
{
// echo "hello"; die;
// Fetch the invoice data based on $invoice_id
$model = new SalesOrderModel();
$data = $model->getSalesPdf($sales_order_id);
$items = $model->getSalesOrderProductsForPdf($sales_order_id);
// print_r($items);die();
// print_r($invoiceItems);die();
// Create an mPDF object
$mpdf = new Mpdf([
'mode' => '',
'format' => 'A5',
'default_font_size' => 0,
'default_font' => '',
'margin_left' => 2,
'margin_right' => 2,
'margin_top' => 6,
'margin_bottom' => 6,
'margin_header' => 6,
'margin_footer' =>-30,
'orientation' => 'P',
]);
$mpdf->autoLangToFont = true; $mpdf->autoScriptToLang = true;
// Set PDF properties
$mpdf->SetTitle('Invoice');
$mpdf->SetAuthor($data[0]->branch_name);
$mpdf->SetCreator('');
$htmlFooter='<div >
<img src="https://cdn.pixabay.com/photo/2012/04/26/14/17/blue-42596_960_720.png"style=margin-top:70px;/> </div>';
$mpdf->setHTMLFooter($htmlFooter);
// Generate the PDF content (HTML)
if ($data[0]->status === 'Draft') {
// Set the watermark text and options
$mpdf->SetWatermarkText('Draft');
$mpdf->showWatermarkText = true;
}
if ($data[0]->status === 'Cancelled') {
// Set the watermark text and options
$mpdf->SetWatermarkText('Cancelled');
$mpdf->showWatermarkText = true;
}
if ($data[0]->status === 'Void') {
// Set the watermark text and options
$mpdf->SetWatermarkText('Void');
$mpdf->showWatermarkText = true;
}
// Generate the PDF content (HTML) with data
$html = view('invoice_pdf_template', ['sales' => $data,'items'=>$items]);
// echo $html;die;
// Load HTML into the mPDF instance
$mpdf->WriteHTML($html);
// Output the PDF to the browser for download
$mpdf->Output('invoice_' . date('Y-m-d H-i-s') . '.pdf', 'D');
}
}

View File

@ -5,7 +5,19 @@ class SalesOrderModel extends Model
{
protected $table = 'sales_order';
protected $primaryKey = 'sales_order_id';
protected $allowedFields = ['sales_order_id','client_id','order_number','status','mobile_no','billing_address','billing_city','billing_state','billing_country','billing_postal_code','total','tax','subtotal','discount','terms_condition','isactive'];
protected $allowedFields = ['sales_order_id','client_id','order_number','branch_id','status','mobile_no','billing_address','billing_city','billing_state','billing_country','billing_postal_code','total','tax','subtotal','discount','terms_condition','isactive'];
public function getSalesPdf($sales_order_id){
return $this->db->table('sales_order')
->where('sales_order_id', $sales_order_id)
->join('client as C','C.client_id= sales_order.client_id','left')
->join('branches as B','B.branch_id = sales_order.branch_id','left')
->select('sales_order.*,C.client_name,C.mobile_no,C.address,C.city,C.state')
->select('B.branch_name ,B.address as company_address,B.city as company_city,B.state as company_state,B.postal_code as company_postal_code,B.mobile_no as company_mobile_no')
->get()
->getResult();
}
public function getSalesOrdersWithProducts()
{
@ -25,7 +37,19 @@ class SalesOrderModel extends Model
// Get the results
return $this->findAll();
}
public function getSalesOrderProductsForPdf($sales_order_id)
{
// Select required fields from the sales_order_product table
$result = $this->db->table('sales_order_product')
->where('sales_order_product.sales_order_id', $sales_order_id)
->join('products', 'products.product_id = sales_order_product.product_id')
->select('sales_order_product.*, products.product_name')
->get()
->getResult();
return $result;
}
}
?>

View File

@ -0,0 +1,292 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<style>
/* Add your CSS styles here to format the invoice for mPDF */
body {
font-family: 'Times New Roman', Times, sans-serif;
font-size: 12px; /* Change this value to your desired font size */
}
/* Style for the main table with border */
table.main-table {
width: 100%;
border-collapse: collapse;
border: -0.5px solid black; /* Add a border around the entire invoice */
}
table.main-table th,
table.main-table td {
border: none; /* Remove borders from all cells inside the main table */
padding: 8px;
}
/* Style for the table containing business details */
table.business-details-table {
width: 100%;
border-collapse: collapse;
}
table.business-details-table td {
padding: 8px;
text-align: left;
}
/* Style for the business logo and title */
.business-logo-container {
text-align: center;
}
img.business-logo {
max-width: 200px; /* Adjust the size of the logo */
}
/* Style for the business name */
.business-name {
font-size: 16px;
font-weight: bold;
margin-top: 10px;
}
/* Style for the table containing invoice info */
table.invoice-info-table {
width: 100%;
}
table.invoice-info-table th,
table.invoice-info-table td {
text-align: right;
}
/* Style for the addresses table */
table.addresses-table {
width: 100%;
}
table.addresses-table th {
text-align: left;
}
/* Style for the billing and shipping addresses */
.billing-address, .shipping-address {
width: 50%;
}
/* Style for the invoice-related table */
table.invoice-related-table {
width: 100%;
border-collapse: collapse;
}
table.invoice-related-table th,
table.invoice-related-table td {
border: none; /* Remove borders from all cells in the invoice items table */
padding: 8px;
text-align: center; /* Center-align text in cells */
}
table.invoice-related-table th {
background-color: #f2f2f2;
font-weight: bold;
}
/* Style for the business stamp and terms */
.business-stamp, .terms {
text-align: center;
margin-top: 20px;
}
.subtotal-table {
width: 100%;
margin-top: 20px;
}
.subtotal-table table {
width: 100%;
border-collapse: collapse;
border: 1px solid black; /* Add a border around the subtotal table */
}
.subtotal-table th,
.subtotal-table td {
border: none; /* Remove borders from cells inside the subtotal table */
padding: 8px;
text-align: right;
}
.subtotal-table th {
background-color: #f2f2f2;
font-weight: bold;
}
.subtotal-table td:last-child {
font-weight: bold; /* Make the last column (total values) bold */
}
td.invoice-number {
font-size: 18px; /* Increase font size to your desired value */
/* Highlight background color */
font-weight: bold; /* Make the text bold */
}
p {
margin-top: 0;
margin-bottom: 0rem;
}
</style>
</head>
<body>
<table class="main-table">
<tr>
<td>
<table class="business-details-table">
<?php foreach ($sales as $value) : ?>
<tr>
<td class="business-logo-container"style="font-size: 25px;
font-weight: bold;">
<!-- <img src="https://vijayabharathambooks.com/wp-content/uploads/2021/09/vijaya-bharatham-logo-8pt.png" alt="Business Logo" class="business-logo"> -->
THE MECHANIC
</td>
</tr>
<tr>
<td>
<p><?= $value->company_address ?>,<br>
<?= $value->company_city ?>,
<?= $value->company_state ?>
<?= $value->company_postal_code ? " - ".$value->company_postal_code:"" ?>.</p>
<p><?= $value->company_mobile_no ?></p>
</td>
</tr>
<?php endforeach; ?>
</table>
</td>
<td>
<table class="invoice-info-table">
<?php foreach ($sales as $value) : ?>
<tr>
<th><?php echo ($value->order_number) ? 'Order # ' . $value->order_number : 'Invoice # ' . $value->invoice_number; ?></th>
</tr>
<tr>
<th>Invoice Date : <?= date('d-m-Y', strtotime($value->created_at)) ?></th>
</tr>
<?php endforeach; ?>
</table>
</td>
</tr>
</table>
<table class="addresses-table">
<tr>
<th class="billing-address">Billing Address</th>
</tr>
<tr>
<td class="billing-address">
<?php foreach ($sales as $value) : ?>
<?= $value->client_name ?><br>
<?= $value->address." ," ?><br>
<?= $value->city ?>&nbsp;<?= $value->state?>
<?= $value->billing_postal_code ." - "?>
<?= $value->billing_country ? $value->billing_country . "." : $value->billing_country ?><br>
<?= $value->mobile_no." ." ?>
<?php endforeach; ?>
</td>
<!-- <td class="shipping-address">
</td> -->
</tr>
</table>
<br> <br>
<table class="invoice-related-table">
<thead>
<tr>
<th>S.no</th>
<th>Item Name</th>
<th>Qty</th>
<th>Rate</th>
<th>Total</th>
</tr>
</thead>
<tbody>
<?php $serialNumber = 1; ?>
<?php foreach ($items as $item) : ?>
<tr>
<td>
<?= $serialNumber++; ?>
</td>
<td><?= $item->product_name ?></td>
<td><?= $item->qty ?></td>
<td><?= number_format($item->net_price, 2, '.', ',') ?></td>
<td><?= number_format($item->amount, 2, '.', ',') ?></td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<table class="subtotal-table">
<?php foreach ($sales as $value) : ?>
<tr>
<td colspan="5" align="right">Subtotal : &nbsp;&nbsp;<?= number_format($value->subtotal, 2, '.', ',') ?></td>
</tr>
<tr>
<td colspan="5" align="right">Tax : &nbsp;&nbsp;<?= number_format($value->tax, 2, '.', ',') ?></td>
</tr>
<!-- -->
<?php if ($value->discount!=0): ?>
<!-- Set Balance if status is draft and paid is 0 -->
<tr>
<td colspan="5" align="right">Discount : &nbsp;&nbsp;<?= number_format($value->discount, 2, '.', ',') ?></td>
</tr>
<?php endif; ?>
<tr>
<td colspan="5" align="right">Total : &nbsp;&nbsp;<?= number_format($value->total, 2, '.', ',') ?></td>
</tr>
<?php if ($value->status === 'Approved'): ?>
<tr>
<td colspan="5" align="right">Paid : &nbsp;&nbsp;<?= number_format($value->total_amount, 2, '.', ',') ?></td>
</tr>
<?php endif; ?>
<?php endforeach; ?>
</table>
<div class="business-stamp">
</div>
<div class="terms">
<p>Thank you!</p>
<!-- <if(!empty($value->notes)){
<br><p style="text-align: left !important;"><b>Notes:</b> $value->notes; ?></p>
} ?> -->
</div>
<!-- ... (your existing HTML template) -->
<!-- Add this to the end of your HTML template -->
<!-- <img src="https://cdn.pixabay.com/photo/2012/04/26/14/17/blue-42596_960_720.png" /> -->
</body>
</html>

View File

@ -44,7 +44,10 @@
<tbody>
<?php foreach ($sales as $value) :
<?php
foreach ($sales as $value) :
if ($value['isactive'] == 1) : ?>
<tr>
<td><?= $value['order_number']; ?></td>
@ -57,6 +60,9 @@
<td><?= $value['total']; ?></td>
<td>
<a href="<?= "new_sale/" . $value['sales_order_id']; ?>" class="edit-button"><i class="ri-pencil-line"></i></a>
<?php if ($value['status'] == 'InvoiceGenerated') : ?>
<a href="<?= "download_invoice/" . $value['sales_order_id']; ?>" class="edit-button"><i class="ri-file-download-line"></i></a>
<?php endif; ?>
<a href="<?= "delete_sale/" . $value['sales_order_id']; ?>" class="delete-button"><i class="ri-delete-bin-line"></i></a>
</td>