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/Expense.php b/app/Controllers/Expense.php index a9be54aa..3d545ab0 100755 --- a/app/Controllers/Expense.php +++ b/app/Controllers/Expense.php @@ -48,8 +48,17 @@ class Expense extends BaseController $this->loadViews("expense_list", $this->global, $data, NULL); } + private function generateSerialNumber($financialYear, $lastSerial) + { + // If no last serial number exists, start with 00001 + $lastNumber = $lastSerial ? (int)explode('/', $lastSerial)[1] : 0; + $newNumber = str_pad($lastNumber + 1, 5, '0', STR_PAD_LEFT); + return "$financialYear/$newNumber"; + } + public function addExpense() { + try{ $file = $this->request->getFile('transporterfile'); $fileName = ''; if ($file->isValid() && !$file->hasMoved()) { @@ -59,6 +68,28 @@ class Expense extends BaseController $status = $this->request->getPost('status'); $paymentMethod = $status === 'Paid' ? $this->request->getPost('payment_method') : 0; + + // Fetch the current month + $currentMonth = date('n'); // 'n' gives the month without leading zeros (1-12) + + // Calculate the current financial year + if ($currentMonth >= 4) { // If it's April or later + $startYear = date('Y'); // Current year + $endYear = $startYear + 1; // Next year + } else { // If it's January, February, or March + $endYear = date('Y'); // Current year + $startYear = $endYear - 1; // Previous year + } + + // Format the financial year as "yy-yy" + $financialYear = substr($startYear, -2) . '-' . substr($endYear, -2); + + // Fetch the last serial number for the financial year + $lastSerial = $this->expense_model->getLastSerialNumber($financialYear); + + // Generate the next serial number + $newSerialNumber = $this->generateSerialNumber($financialYear, $lastSerial); + $data = [ 'transporter_file' => $fileName, @@ -70,14 +101,21 @@ class Expense extends BaseController 'sgst' => $this->request->getPost('sgst'), 'igst' => $this->request->getPost('igst'), 'total' => $this->request->getPost('total'), + 'bill_no' => $this->request->getPost('bill_no'), + 'bill_date' => $this->request->getPost('bill_date'), + 'serial_number' => $newSerialNumber, ]; - + $insert_id = $this->expense_model->insertExpense($data); if ($insert_id) { return json_encode('true'); } else { return json_encode('false'); } + } catch (\Exception $e) { + // Handle the exception + echo "Error: " . $e->getMessage(); + } } public function getExpenseDetails() @@ -117,6 +155,8 @@ class Expense extends BaseController 'sgst' => $this->request->getPost('sgst'), 'igst' => $this->request->getPost('igst'), 'total' => $this->request->getPost('total'), + 'bill_no' => $this->request->getPost('bill_no'), + 'bill_date' => $this->request->getPost('bill_date'), ]; if(!empty($fileName)){ $data['transporter_file'] = $fileName; 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/Models/Expense_model.php b/app/Models/Expense_model.php index d328b7ee..524e8ba3 100755 --- a/app/Models/Expense_model.php +++ b/app/Models/Expense_model.php @@ -9,9 +9,20 @@ class Expense_model extends Model protected $primaryKey = 'id'; // Primary key protected $allowedFields = [ - 'transporter_file', 'supplier_id', 'remarks', 'item_description', 'cost', 'cgst', 'sgst', 'igst', 'total', + 'serial_number' , 'transporter_file', 'supplier_id', 'remarks', 'item_description', 'cost', 'cgst', 'sgst', 'igst', 'total', 'bill_no' ,'bill_date' ]; + public function getLastSerialNumber($financialYear) + { + return $this->db->table('t_expense') + ->select('serial_number') + ->like('serial_number', "$financialYear/", 'after') + ->orderBy('serial_number', 'DESC') + ->limit(1) + ->get() + ->getRow('serial_number'); + } + // Retrieve all active expenses public function getAllExpense($fromDate,$toDate) { return $this->join('t_supplierdetailsn', 't_expense.supplier_id = t_supplierdetailsn.SupplierID') diff --git a/app/Views/POlist.php b/app/Views/POlist.php index 680daacf..4c118748 100755 --- a/app/Views/POlist.php +++ b/app/Views/POlist.php @@ -47,25 +47,7 @@ align-items: center; } - .dataTables_wrapper .dataTables_length { - /* float: left; */ - } - - .dataTables_wrapper .dt-buttons, - .dataTables_wrapper .dataTables_filter { - /* float: right; */ - /* margin-left: 10px; */ - } - - .dataTables_wrapper .dt-buttons { - /* margin-top: 10px; */ - /* margin-bottom: 10px; */ - } - - .dataTables_wrapper .dataTables_filter { - /* margin-top: 10px; */ - /* margin-bottom: 10px; */ - } + @@ -267,7 +249,13 @@ var table = $('#po_list').DataTable({ dom: 'Blfrtip', buttons: [ - 'excel', 'pdf' + { + extend: 'excel', + text: 'Excel', + exportOptions: { + columns: ':not(:last-child)' // Exclude the last column + } + } ], pageLength: 10, lengthMenu: [ diff --git a/app/Views/expense_list.php b/app/Views/expense_list.php index df060602..ec997c70 100755 --- a/app/Views/expense_list.php +++ b/app/Views/expense_list.php @@ -55,6 +55,11 @@ background-color: white; color: red; } + + th, + td { + white-space: nowrap; + }
@@ -108,8 +113,11 @@ Created Date + Non-IGRNO Supplier Name Item Description + Bill No + Bill Date Cost CGST SGST @@ -138,7 +146,7 @@ } ?> - +
@@ -151,6 +159,13 @@
+ + + format('d-m-Y'); + ?> + @@ -214,12 +229,29 @@
+
+
+ +
+
+ +
+
+ +
+
+ +
+
+ +
+
- +
@@ -227,7 +259,7 @@
- +
@@ -235,7 +267,7 @@
- +
@@ -243,7 +275,7 @@
- +
@@ -251,7 +283,7 @@
- +
@@ -287,6 +319,13 @@
- - - - -