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 = '
| Invoice Date | +Invoice No | +Client Name | +Product | +Quantity | +Rec Qty | +Rate | +Sub Total | +GST | +Total | +Status | +
|---|---|---|---|---|---|---|---|---|---|---|
| ' . 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 . ' | +