purchase PDF
This commit is contained in:
parent
fb0a825faf
commit
86529db325
@ -201,6 +201,8 @@ $routes->get('dashboard', 'Users::dashboard');
|
||||
$routes->post("delete_purchase_product", "Purchase::delete_purchase_product");
|
||||
$routes->get("download_purchase_invoice/(:any)", "Purchase::download_purchase_invoice/$1");
|
||||
$routes->get("reorder_purchase/(:any)", "Purchase::reorder_purchase/$1");
|
||||
$routes->get("preview_purchase/(:any)", "Purchase::preview_purchase/$1");
|
||||
$routes->get("download_purchase/(:any)", "Purchase::download_purchase/$1");
|
||||
// Purchase End's//
|
||||
|
||||
|
||||
|
||||
@ -10,6 +10,7 @@ use App\Models\BusinessModel;
|
||||
use App\Models\PurchaseOrderChildModel;
|
||||
use Mpdf\Mpdf;
|
||||
use App\Helpers\MailHelper;
|
||||
use CodeIgniter\API\ResponseTrait;
|
||||
|
||||
|
||||
class Purchase extends BaseController
|
||||
@ -21,6 +22,8 @@ class Purchase extends BaseController
|
||||
protected $BranchModel;
|
||||
protected $BusinessModel;
|
||||
protected $PurchaseOrderChildModel;
|
||||
use ResponseTrait;
|
||||
|
||||
public function __construct()
|
||||
{
|
||||
$this->session = session();
|
||||
@ -490,5 +493,50 @@ public function download_purchase_invoice($purchase_order_id, $mail = null)
|
||||
}
|
||||
|
||||
}
|
||||
public function preview_purchase($purchase_order_id)
|
||||
{
|
||||
|
||||
$data['purchase'] = $this->PurchaseOrderModel->getPurchasePdf($purchase_order_id);
|
||||
$data['items'] = $this->PurchaseOrderModel->getPurchaseOrderProductsForPdf($purchase_order_id);
|
||||
|
||||
$html = view('purchase_pdf_template', $data);
|
||||
return $this->respond(['status' => 'success','code' => 200,'data' => $html],200);
|
||||
}
|
||||
|
||||
public function download_purchase($purchase_order_id)
|
||||
{
|
||||
if(!$this->session->has('logged_user')) { return redirect()->to(base_url()); }
|
||||
|
||||
|
||||
$data['purchase'] = $this->PurchaseOrderModel->getPurchasePdf($purchase_order_id);
|
||||
$data['items'] = $this->PurchaseOrderModel->getPurchaseOrderProductsForPdf($purchase_order_id);
|
||||
|
||||
$mpdf = new Mpdf([
|
||||
'mode' => '',
|
||||
'format' => 'A4',
|
||||
'default_font_size' => 0,
|
||||
'default_font' => '',
|
||||
// 'margin_right' => 1,
|
||||
'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('Purchase Order');
|
||||
$mpdf->SetAuthor($data['purchase'][0]->order_number);
|
||||
$mpdf->SetCreator('');
|
||||
|
||||
|
||||
// Generate the PDF content (HTML) with data
|
||||
$html = view('purchase_pdf_template', $data);
|
||||
$mpdf->WriteHTML($html);
|
||||
date_default_timezone_set('Asia/Kolkata');
|
||||
$mpdf->Output($data['purchase'][0]->order_number .'_' . date('Y-m-d H-i-s') . '.pdf', 'D');
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@ -36,7 +36,7 @@ class PurchaseOrderModel extends Model
|
||||
->join('branches as B','B.branch_id = purchase_order.branch_id','left')
|
||||
->join('vendor as V','V.vendor_id = purchase_order.vendor_id','left')
|
||||
->select('purchase_order.*')
|
||||
->select('V.vendor_name,V.contact_person_mobile1,V.address as vendor_address,V.city as vendor_city,V.state,V.postal_code as vendor_postal,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.contact_1 as company_mobile_no')
|
||||
->select('V.vendor_name,V.contact_person_mobile1,V.address as vendor_address,V.city as vendor_city,V.state,V.postal_code as vendor_postal,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.contact_1 as company_mobile_no,B.gstno as company_gstno')
|
||||
|
||||
->get()
|
||||
->getResult();
|
||||
|
||||
@ -102,6 +102,7 @@
|
||||
<a href="<?= "reorder_purchase/" . $value['purchase_order_id']; ?>" class="dropdown-item" onclick="datatablePurchaseOrder('purchase_tr_<?php echo $index+1; ?>')"><i class="fa fa-retweet"></i>Pending Reorder</a>
|
||||
<?php } ?>
|
||||
<a href="<?= "download_purchase_invoice/" . $value['purchase_order_id']; ?>" class="edit-button dropdown-item" onclick="datatablePurchaseOrder('purchase_tr_<?php echo $index+1; ?>')"><i class="ri-download-2-fill"></i>Download</a>
|
||||
<a href="#" data-purchase_order-id="<?= $value['purchase_order_id']; ?>" class="dropdown-item preview-purchaseorder" href="#" title="Preview PurchaseOrder"><i class="ri-book-read-line"></i>Preview PO</a>
|
||||
</div>
|
||||
</div>
|
||||
</td>
|
||||
@ -120,6 +121,24 @@
|
||||
|
||||
</div>
|
||||
<?php include('layout/footer.php'); ?>
|
||||
<div class="modal fade" id="PreviewPurchaseOrderModal" tabindex="-1" role="dialog" aria-labelledby="PreviewPurchaseOrderModalLabel" aria-hidden="true">
|
||||
<div class="modal-dialog modal-lg">
|
||||
<div class="modal-content" style="width: 794px; height: 1123px;">
|
||||
<div class="modal-header">
|
||||
<h5 class="modal-title" id="PreviewPurchaseOrderModalLabel"></h5>
|
||||
|
||||
<a href="#" class="ri-download-2-fill ml-3 text-muted font-18" id="downloadPurchaseButton" title="Download Purchase"></a>
|
||||
<a href="#" class="ri-printer-fill ml-3 text-muted font-18" id="printPurchaseButton" title="Print Invoice"></a>
|
||||
<button type="button" class="close" data-dismiss="modal" aria-label="Close" style="font-size: 27px; margin-bottom: 2px;">
|
||||
<span aria-hidden="true">×</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="modal-body" style="font-family: Times New Roman, Times, sans-serif !important; font-size: 12px !important;">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
var datatable_purchase_order ='';
|
||||
@ -142,6 +161,79 @@
|
||||
]
|
||||
});
|
||||
|
||||
$(document).on('click', '.preview-purchaseorder', function() {
|
||||
var Id = $(this).data('purchase_order-id');
|
||||
console.log(Id);
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'preview_purchase/'+Id,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.status == "success") {
|
||||
$('#PreviewPurchaseOrderModal').modal('show');
|
||||
$('#PreviewPurchaseOrderModalLabel').text('Purchase Order Preview ');
|
||||
$('#PreviewPurchaseOrderModal .modal-body').html(response.data);
|
||||
$('#downloadPurchaseButton').attr('href', '<?= base_url("download_purchase/") ?>' + Id);
|
||||
$('#printPurchaseButton').attr('data-id', Id);
|
||||
}else{
|
||||
$('#PreviewPurchaseOrderModal').modal('hide');
|
||||
$('#PreviewPurchaseOrderModalLabel').text('');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error response here
|
||||
console.error(xhr.responseText);
|
||||
$('#PreviewPurchaseOrderModal').modal('hide');
|
||||
$('#PreviewPurchaseOrderModalLabel').text('');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
$(document).on('click', '#printPurchaseButton', function() {
|
||||
var Id = $(this).data('id');
|
||||
$.ajax({
|
||||
type: 'GET',
|
||||
url: 'preview_purchase/'+Id,
|
||||
dataType: 'json',
|
||||
success: function(response) {
|
||||
if (response.status == "success") {
|
||||
|
||||
var newWin = window.open("", "_blank", "width=600,height=400");
|
||||
newWin.document.write("<html><head><title>Print</title>");
|
||||
newWin.document.write(`
|
||||
<style>
|
||||
@media print {
|
||||
@page {
|
||||
size: A4; /* Set default print size to A4 */
|
||||
margin: 1cm; /* Set margin as per requirement */
|
||||
}
|
||||
body {
|
||||
font-family: Arial, sans-serif;
|
||||
}
|
||||
}
|
||||
</style>
|
||||
`);
|
||||
newWin.document.write("</head><body>");
|
||||
newWin.document.write(response.data);
|
||||
newWin.document.write("</body></html>");
|
||||
newWin.document.close();
|
||||
newWin.print();
|
||||
newWin.close();
|
||||
|
||||
|
||||
}else{
|
||||
$('#PreviewPurchaseModal').modal('hide');
|
||||
$('#PreviewPurchaseModalLabel').text('');
|
||||
}
|
||||
},
|
||||
error: function(xhr, status, error) {
|
||||
// Handle error response here
|
||||
console.error(xhr.responseText);
|
||||
$('#PreviewPurchaseModal').modal('hide');
|
||||
$('#PreviewPurchaseModalLabel').text('');
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
//Start DataTable Paging is session is set
|
||||
var savedPage = sessionStorage.getItem('currentPage');
|
||||
|
||||
91
app/Views/purchase_pdf_template.php
Executable file
91
app/Views/purchase_pdf_template.php
Executable file
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user