New changes in BBNepal

This commit is contained in:
Roshan 2024-10-17 17:06:13 +05:45
parent 4ac5a5e491
commit 7008ec0310
7 changed files with 261 additions and 38 deletions

View File

@ -162,7 +162,7 @@ class Reports extends CI_Controller
$data['pageTitle'] = "Profit & Loss Statement";
loadView("accounts/pl", $data);
break;
case 'pl':
case 'pl':
if (!isset($_POST['fromDate'])) {
$data['fromDate'] = null;
}
@ -170,12 +170,12 @@ class Reports extends CI_Controller
$data['toDate'] = null;
}
if (isset($_POST)) {
$data = $_POST;
$data = $_POST;
}
$data['fiscalStart'] = NepaliToEnglishDate($data['fromDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_from);
$data['fiscalEnd'] = NepaliToEnglishDate($data['toDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_to);
$data['pageTitle'] = "Profit & Loss Statement";
loadView("accounts/pl_new", $data);
loadView("accounts/pl_new", $data);
break;
case 'pl_grouped':

View File

@ -77,8 +77,8 @@ class Purchases extends CI_Controller
'remarks' => filter_var($_POST['remarks']),
'status' => 1,
);
pre($_POST);
die;
// pre($_POST);
// die;
//$this->db->insert('tbl_purchases', $TableData);
redirect("inventory/purchases/list");
}
@ -93,8 +93,22 @@ class Purchases extends CI_Controller
$this->db->delete('tbl_purchasedetails');
redirect("inventory/purchases/list");
break;
case 'purchase_register':
$data['PurchaseRecords'] = $this->MPurchases->getPurchaseRecords();
case 'purchase_register':
if (!isset($_POST['fromDate'])) {
$data['fromDate'] = null;
}
if (!isset($_POST['toDate'])) {
$data['toDate'] = null;
}
if (isset($_POST)) {
$data = $_POST;
}
$data['fiscalStart'] = NepaliToEnglishDate($data['fromDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_from);
$data['fiscalEnd'] = NepaliToEnglishDate($data['toDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_to);
$data['pageTitle'] = "Sales & Register";
$data['PurchaseRecords'] = $this->MPurchases->getPurchaseRecords($data['fiscalStart'],$data['fiscalEnd']);
loadView("inventory/purchases/register", $data);
break;

View File

@ -10,8 +10,8 @@ class Sales extends CI_Controller
checkLogin();
}
public function _remap($alias = "", $params = array())
{
$data['dataValue'] = $this->session;
@ -62,13 +62,27 @@ class Sales extends CI_Controller
}
// print_r($TableData);
// die;
// $this->db->where('sales_id', $sales_id);
$this->MStocks->addSalesToStock($this->db->where('sales_id', $sales_id)->get('tbl_salesdetails')->result());
// $this->db->where('sales_id', $sales_id);
$this->MStocks->addSalesToStock($this->db->where('sales_id', $sales_id)->get('tbl_salesdetails')->result());
redirect("inventory/sales/list");
break;
case 'sales_register':
$data['SalesRecords'] = $this->MSales->getSalesRecords();
if (!isset($_POST['fromDate'])) {
$data['fromDate'] = null;
}
if (!isset($_POST['toDate'])) {
$data['toDate'] = null;
}
if (isset($_POST)) {
$data = $_POST;
}
$data['fiscalStart'] = NepaliToEnglishDate($data['fromDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_from);
$data['fiscalEnd'] = NepaliToEnglishDate($data['toDate'] ?? $this->session->userdata['FiscalYear']->fiscalyear_to);
$data['pageTitle'] = "Sales & Register";
$data['SalesRecords'] = $this->MSales->getSalesRecords($data['fiscalStart'],$data['fiscalEnd']);
loadView("inventory/sales/register", $data);
break;
case 'details':
@ -105,19 +119,18 @@ class Sales extends CI_Controller
redirect("inventory/sales/list");
break;
case 'getunitbyitem':
$id = $this->uri->segment(4);
$unit = $this->MStocks->getUnitByItemId($id);
echo json_encode($unit);
break;
case 'getunitbyitem':
$id = $this->uri->segment(4);
$unit = $this->MStocks->getUnitByItemId($id);
echo json_encode($unit);
break;
default:
$data['SalesRecords'] = $this->MSales->getSalesRecords();
loadView("inventory/sales/list", $data);
}
}
// public function getUnitByItemId($id) {
// $unitName = $this->MStocks->getUnitByItemId($id);

View File

@ -39,9 +39,9 @@ class MPurchases extends CI_Model
}
return $PurchaseRecords;
}
public function getPurchaseRecords()
public function getPurchaseRecords($fromDate, $toDate)
{
$PurchaseRecords = $this->db->where("status", 1)->get("tbl_purchases")->result();
$PurchaseRecords = $this->db->where("status", 1)->where("created_on between '$fromDate' AND '$toDate'")->get("tbl_purchases")->result();
foreach ($PurchaseRecords as $PurchaseRecord) {
$PurchaseRecord->Details = $this->getPurchaseDetails($PurchaseRecord->purchase_id);
$PurchaseRecord->TotalPurchase = $this->getTotalPurchaseAmount($PurchaseRecord->purchase_id);

View File

@ -39,9 +39,9 @@ class MSales extends CI_Model
}
return $SalesRecords;
}
public function getSalesRecords()
public function getSalesRecords($fromDate, $toDate)
{
$SalesRecords = $this->db->where("status", 1)->get("tbl_sales")->result();
$SalesRecords = $this->db->where("status", 1)->where("created_on between '$fromDate' AND '$toDate'")->get("tbl_sales")->result();
foreach ($SalesRecords as $SalesRecord) {
$SalesRecord->Details = $this->getSalesDetails($SalesRecord->sales_id);
$SalesRecord->totalsales = $this->getTotalSalesAmount($SalesRecord->sales_id);
@ -57,7 +57,7 @@ class MSales extends CI_Model
}
$this->db->group_by('items_id');
$query = $this->db->get();
$SalesRecords=$query->result();
$SalesRecords = $query->result();
foreach ($SalesRecords as $SalesRecord) {
$SalesRecord->Item = $this->db->where("item_id", $SalesRecord->items_id)->get("tbl_items")->row();
}

View File

@ -7,21 +7,90 @@
<div class="card-header">
<!-- <h5 class="m-0"><?php echo $pageTitle; ?> <?php showCreateButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/add", "Create New " . $pageTitle); ?></h5> -->
</div>
<form class="ml-4" method="post" action="<?php echo base_url('accounts/reports/pl'); ?>" id="FilterForm">
<!-- button with a dropdown -->
<div class="btn-group">
<button type="button" class="btn btn-success btn-sm dropdown-toggle" data-toggle="dropdown" data-offset="-52">
Filters
</button>
<div class="dropdown-menu" role="menu">
<div class="form-group p-2 pb-0">
<div class="col">
<div class="form-group">
<label for="fromDate"><?php myLang("Starting Period"); ?></label>
<input type="text" class="form-control " name="fromDate" value="<?php echo (isset($_POST['fromDate'])) ? $_POST['fromDate'] : NepaliDate($this->session->FiscalYear->fiscalyear_from); ?>" data-start="<?php echo $fiscalStart; ?>" data-end="<?php echo $fiscalEnd; ?>" id="fromDate" aria-describedby="helpId_fromDate" placeholder="Starting Period">
</div>
<div class="form-group">
<label for="toDate"><?php myLang("Ending Period"); ?></label>
<input type="text" class="form-control " name="toDate" value="<?php echo (isset($_POST['toDate'])) ? $_POST['toDate'] : NepaliDate($this->session->FiscalYear->fiscalyear_to); ?>" data-start="<?php echo $fiscalStart; ?>" data-end="<?php echo $fiscalEnd; ?>" id="toDate" aria-describedby="helpId_toDate" placeholder="Ending Period">
</div>
</div>
<div class="dropdown-divider"></div>
<!-- <div class="form-check">
<input class="form-check-input" type="checkbox">
<label class="form-check-label">Select
All</label>
</div> -->
<div class="form-check">
<!-- <input type="hidden" name="showOB" value="not"> -->
<input type="checkbox" class="form-check-input " name="showOB" id="showOB" aria-describedby="helpId_showOB" placeholder="Show Opening Balance" <?php echo (isset($_POST['showOB'])) ? "CHECKED" : ""; ?>>
<!-- <input class="form-check-input" type="checkbox"> -->
<label class="form-check-label" for="showOB">Opening</label>
</div>
<div class="form-check">
<!-- <input class="form-check-input" type="checkbox"> -->
<input type="checkbox" class="form-check-input " name="showClosing" id="showClosing" aria-describedby="helpId_showClosing" placeholder="Show Closing Balance" <?php echo (isset($_POST['showClosing'])) ? "CHECKED" : ""; ?>>
<label class="form-check-label" for="showClosing">Closing</label>
</div>
<div class="form-check">
<!-- <input class="form-check-input" type="checkbox" checked> -->
<input type="checkbox" class="form-check-input" name="showPeriod" id="showPeriod" aria-describedby="helpId_showPeriod" placeholder="Show Periodic Balance" <?php echo (isset($_POST['showPeriod'])) ? "CHECKED" : "CHECKED"; ?>>
<label class="form-check-label" for="showPeriod">Period</label>
</div>
</div>
<div class="dropdown-divider"></div>
<div class="form-group p-2 pb-0 text-right">
<button type="button" class="btn btn-info btn-sm " style="width:60px;height:30px;" onclick="resetForm()">Reset</button>
<button type="submit" class="btn btn-primary mr-2 btn-sm" style="width:60px;height:30px;">Search </button>
</div>
</div>
</div>
<div class="btn-group">
<!-- <button type="submit" class="btn btn-warning btn-sm " data-toggle="dropdown" data-offset="-52">
Export
</button> -->
<!-- <button type="submit" onclick="exportTableToCSV('accounts_data.csv')" class="btn btn-warning btn-sm " data-toggle="dropdown" data-offset="-52">
Export
</button> -->
<button type="submit" id="downloadCsv" class="btn btn-warning btn-sm ">
Export csv
</button>
<!-- <div class="dropdown-menu" role="menu">
<a href="#" class="dropdown-item">Export</a>
<a href="#" class="dropdown-item">Pdf</a>
<div class="dropdown-divider"></div>
<a href="#" class="dropdown-item">View calendar</a>
</div> -->
</div>
<button class="btn btn-secondary toggle-collapse btn-sm" id="toggleShowAll">Toggle Collapse</button>
</form>
<div class="card-body">
<?php $TableData = $this->db->query("select * from tbl_purchases where status=1")->result(); ?>
<table class="table table-bordered table-striped dataTable">
<table class="table table-bordered table-striped dataTable" id="myTable">
<thead>
<tr>
<th width="3%" class="text-center"><?php myLang('S.N'); ?></th>
<th width="10%" class="col-1"><?php myLang('Date'); ?></th>
<th class="table-col col-9"><?php myLang('Purchase Transaction'); ?></th>
<th width="8%"class="col-2"><?php myLang('Amount'); ?></th>
<th width="8%" class="col-2"><?php myLang('Amount'); ?></th>
<td class="col-1 text-center"><b>Action</b></th>
</tr>
</thead>
<tbody>
<?php $a = 0; $n=0;
<?php $a = 0;
$n = 0;
foreach ($PurchaseRecords as $TableRow) : $a++;
$id = $TableRow->purchase_id; ?>
<tr>
@ -49,4 +118,41 @@
</div>
</div>
</div>
</div>
</div>
<!-- pdf document -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script>
document.getElementById('downloadCsv').addEventListener('click', function() {
const table = document.getElementById('myTable');
const rows = Array.from(table.rows);
const data = [];
rows.forEach((row) => {
const cells = Array.from(row.cells);
const rowData = [];
cells.forEach((cell) => {
// Handle colspan
const colspan = cell.colSpan || 1;
for (let i = 0; i < (colspan - 1); i++) {
rowData.push(''); // Fill empty cells for merged columns
}
for (let i = 0; i < 1; i++) {
rowData.push(cell.innerText.trim());
}
// Fill empty cells for colspan
});
data.push(rowData);
});
// Create a worksheet
const worksheet = XLSX.utils.aoa_to_sheet(data);
const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
// Export to Excel
XLSX.writeFile(workbook, 'table.xlsx');
});
</script>
<!-- pdf document ends-->

View File

@ -6,13 +6,66 @@
<div class="card card-primary card-outline">
<div class="card-header">
<h5 class="m-0 card-title"><?php echo $pageTitle; ?> </h5><a href="<?php echo site_url($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/create"); ?>" class="btn btn-sm btn-primary float-right">Create New <?php echo $pageTitle; ?></a>
<!-- Filter Start -->
<form method="post" action="" id="FilterForm">
<!-- button with a dropdown -->
<div class="btn-group">
<button type="button" class="btn btn-success btn-sm dropdown-toggle" data-toggle="dropdown" data-offset="-52">
Filters
</button>
<div class="dropdown-menu" role="menu">
<div class="form-group p-2 pb-0">
<div class="col">
<div class="form-group">
<label for="fromDate"><?php myLang("Starting Period"); ?></label>
<input type="text" class="form-control " name="fromDate" value="<?php echo (isset($_POST['fromDate'])) ? $_POST['fromDate'] : NepaliDate($this->session->FiscalYear->fiscalyear_from); ?>" data-start="<?php echo $fiscalStart; ?>" data-end="<?php echo $fiscalEnd; ?>" id="fromDate" aria-describedby="helpId_fromDate" placeholder="Starting Period">
</div>
<div class="form-group">
<label for="toDate"><?php myLang("Ending Period"); ?></label>
<input type="text" class="form-control " name="toDate" value="<?php echo (isset($_POST['toDate'])) ? $_POST['toDate'] : NepaliDate($this->session->FiscalYear->fiscalyear_to); ?>" data-start="<?php echo $fiscalStart; ?>" data-end="<?php echo $fiscalEnd; ?>" id="toDate" aria-describedby="helpId_toDate" placeholder="Ending Period">
</div>
</div>
<div class="dropdown-divider"></div>
<div class="form-check">
<!-- <input type="hidden" name="showOB" value="not"> -->
<input type="checkbox" class="form-check-input " name="showOB" id="showOB" aria-describedby="helpId_showOB" placeholder="Show Opening Balance" <?php echo (isset($_POST['showOB'])) ? "CHECKED" : ""; ?>>
<!-- <input class="form-check-input" type="checkbox"> -->
<label class="form-check-label" for="showOB">Opening</label>
</div>
<div class="form-check">
<!-- <input class="form-check-input" type="checkbox"> -->
<input type="checkbox" class="form-check-input " name="showClosing" id="showClosing" aria-describedby="helpId_showClosing" placeholder="Show Closing Balance" <?php echo (isset($_POST['showClosing'])) ? "CHECKED" : ""; ?>>
<label class="form-check-label" for="showClosing">Closing</label>
</div>
<div class="form-check">
<!-- <input class="form-check-input" type="checkbox" checked> -->
<input type="checkbox" class="form-check-input" name="showPeriod" id="showPeriod" aria-describedby="helpId_showPeriod" placeholder="Show Periodic Balance" <?php echo (isset($_POST['showPeriod'])) ? "CHECKED" : "CHECKED"; ?>>
<label class="form-check-label" for="showPeriod">Period</label>
</div>
</div>
<div class="dropdown-divider"></div>
<div class="form-group p-2 pb-0 text-right">
<button type="button" class="btn btn-info btn-sm " style="width:60px;height:30px;" onclick="resetForm()">Reset</button>
<button type="submit" class="btn btn-primary mr-2 btn-sm" style="width:60px;height:30px;">Search </button>
</div>
</div>
</div>
<div class="btn-group">
<button type="submit" id="downloadCsv" class="btn btn-warning btn-sm ">
Export csv
</button>
</div>
<!-- <button class="btn btn-secondary toggle-collapse btn-sm" id="toggleShowAll">Toggle Collapse</button> -->
</form>
<!-- Filter Ends -->
</div>
<div class="card-body">
<?php $TableData = $this->db->query("select * from tbl_sales where status=1")->result(); ?>
<table class="table table-bordered table-striped dataTable">
<table class="table table-bordered table-striped dataTable" id='myTable'>
<thead>
<tr>
<th class=" col-1 text-center"><?php myLang('ID'); ?></th>
<th class=" col-1 text-center"><?php myLang('ID'); ?></th>
<th class=" col-1 text-center"><?php myLang('Sales Voucher #'); ?></th>
<th class=" col-1 text-center"><?php myLang('Item'); ?></th>
<th class="col-1"><?php myLang('Date'); ?></th>
@ -21,22 +74,22 @@
<th class="text-center" width="5%"> <?php myLang('Action'); ?></th>
</tr>
</thead>
<tbody>
<?php $n=0 ; ?>
<?php foreach ($SalesRecords as $key=>$TableRow) : ?>
<tbody>
<?php $n = 0; ?>
<?php foreach ($SalesRecords as $key => $TableRow) : ?>
<tr>
<td class="text-center"><?php echo ++$n; ?></td>
<td class="text-center"><?php echo $TableRow->sales_id; ?></td>
<td class="text-center"><?php echo ($TableRow->Details[$key]->Item->title) ?? ""; ?></td>
<td><?php echo $TableRow->sales_date; ?></td>
<td><?php echo (($this->myaccounts->getAccountDetails($TableRow->accounts_id)->account_name)?? ""); ?>
</td>
<td><?php echo (($this->myaccounts->getAccountDetails($TableRow->accounts_id)->account_name) ?? ""); ?>
</td>
<td><?php echo myCurrency($TableRow->totalsales); ?></td>
<td class="text-center"><?php showDetailsButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/details/$TableRow->sales_id"); ?>
<?php showDeleteButton($TableRow->sales_id); ?>
</td>
</tr>
<?php endforeach; ?>
<?php endforeach; ?>
<tbody>
</table>
<script>
@ -52,4 +105,41 @@
</div>
</div>
</div>
</div>
</div>
<!-- pdf document -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/xlsx/0.17.0/xlsx.full.min.js"></script>
<script>
document.getElementById('downloadCsv').addEventListener('click', function() {
const table = document.getElementById('myTable');
const rows = Array.from(table.rows);
const data = [];
rows.forEach((row) => {
const cells = Array.from(row.cells);
const rowData = [];
cells.forEach((cell) => {
// Handle colspan
const colspan = cell.colSpan || 1;
for (let i = 0; i < (colspan - 1); i++) {
rowData.push(''); // Fill empty cells for merged columns
}
for (let i = 0; i < 1; i++) {
rowData.push(cell.innerText.trim());
}
// Fill empty cells for colspan
});
data.push(rowData);
});
// Create a worksheet
const worksheet = XLSX.utils.aoa_to_sheet(data);
const workbook = XLSX.utils.book_new();
XLSX.utils.book_append_sheet(workbook, worksheet, 'Sheet1');
// Export to Excel
XLSX.writeFile(workbook, 'table.xlsx');
});
</script>
<!-- pdf document ends-->