diff --git a/app/Config/Routes.php b/app/Config/Routes.php index e6cf6a5a..03225b3d 100755 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -412,6 +412,7 @@ $routes->get('deleteAttachment', 'Sales::deleteAttachment'); $routes->post('saveAttachment', 'Sales::saveAttachment'); $routes->get('sales_invoice', 'Sales::sales_invoice'); $routes->post('sales_invoice', 'Sales::sales_invoice'); +$routes->post('download_sales_invoice', 'Sales::download_sales_invoice'); $routes->post('updateInvRecQty', 'Sales::updateInvRecQty'); // transporter Routes diff --git a/app/Controllers/Sales.php b/app/Controllers/Sales.php index c530c886..48b2656b 100755 --- a/app/Controllers/Sales.php +++ b/app/Controllers/Sales.php @@ -8,6 +8,8 @@ use App\Models\Ipinvoice_model; use App\Models\Ipattachment_model; require_once 'vendor/autoload.php'; +use PhpOffice\PhpSpreadsheet\Spreadsheet; +use PhpOffice\PhpSpreadsheet\Writer\Xlsx; class Sales extends BaseController { @@ -40,6 +42,7 @@ class Sales extends BaseController return $formattedNumber; } + public function sales_dashboard() { $this->global['pageTitle'] = 'Sales Dashboard'; @@ -97,12 +100,12 @@ class Sales extends BaseController { $toDate = date('Y-m-d'); $fromDate = date('Y-m-d', strtotime('-90 days', strtotime($toDate))); - } elseif ($this->request->getMethod() === 'POST') { - $fromDate = $this->request->getPost('fromDate'); - $toDate = $this->request->getPost('toDate'); - $fromDate = date('Y-m-d', strtotime($fromDate)); - $toDate = date('Y-m-d', strtotime($toDate)); - } + } elseif ($this->request->getMethod() === 'POST') { + $fromDate = $this->request->getPost('fromDate'); + $toDate = $this->request->getPost('toDate'); + $fromDate = date('Y-m-d', strtotime($fromDate)); + $toDate = date('Y-m-d', strtotime($toDate)); + } $this->global['pageTitle'] = 'Sales Invoice'; $data['sales_invoice'] = $this->ipinvoice_model->saleInvoiceListing($fromDate , $toDate); @@ -114,6 +117,62 @@ class Sales extends BaseController $this->loadViews("sales_invoice", $this->global, $data, NULL); } + + public function download_sales_invoice() + { + // Fetch data from the model + $fromDate = $this->request->getPost('fromDate'); + $toDate = $this->request->getPost('toDate'); + $fromDate = date('Y-m-d', strtotime($fromDate)); + $toDate = date('Y-m-d', strtotime($toDate)); + + $sales_invoice = $this->ipinvoice_model->saleInvoiceListing($fromDate, $toDate); + + // Start building the table + $html = ' + + + + + + + + + + + + + + + + '; + + foreach ($sales_invoice as $invoice) { + $subtotal = $invoice->item_price * $invoice->item_quantity; + $cgst_amount = ($subtotal * $invoice->cgst) / 100; + $sgst_amount = ($subtotal * $invoice->sgst) / 100; + $total = $subtotal + $cgst_amount + $sgst_amount; + + $html .= ' + + + + + + + + + + + + '; + } + + $html .= '
Invoice DateInvoice NoClient NameProductQuantityRec QtyRateSub TotalGSTTotalStatus
' . date('d-m-Y', strtotime($invoice->invoice_date_created)) . '' . $invoice->invoice_number . '' . $invoice->client_name . '' . $invoice->item_name . '' . number_format($invoice->item_quantity, 2, '.', ',') . '' . (!empty($invoice->received_qty) ? $invoice->received_qty : '') . '' . number_format($invoice->item_price, 2, '.', ',') . '' . number_format($subtotal, 2, '.', ',') . '' . number_format($cgst_amount + $sgst_amount, 2, '.', ',') . '' . number_format($total, 2, '.', ',') . '' . $invoice->status . '
'; + + return $this->response->setJSON(['html' => $html]); + } + // View Invoice function ViewInvoice($InvoiceNO = '') diff --git a/app/Views/includes/new_footer.php b/app/Views/includes/new_footer.php index 8b0502c3..b0902d47 100755 --- a/app/Views/includes/new_footer.php +++ b/app/Views/includes/new_footer.php @@ -59,12 +59,7 @@ - - - - -