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

@ -77,8 +77,8 @@ class Purchases extends CI_Controller
'remarks' => filter_var($_POST['remarks']), 'remarks' => filter_var($_POST['remarks']),
'status' => 1, 'status' => 1,
); );
pre($_POST); // pre($_POST);
die; // die;
//$this->db->insert('tbl_purchases', $TableData); //$this->db->insert('tbl_purchases', $TableData);
redirect("inventory/purchases/list"); redirect("inventory/purchases/list");
} }
@ -94,7 +94,21 @@ class Purchases extends CI_Controller
redirect("inventory/purchases/list"); redirect("inventory/purchases/list");
break; break;
case 'purchase_register': case 'purchase_register':
$data['PurchaseRecords'] = $this->MPurchases->getPurchaseRecords(); 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); loadView("inventory/purchases/register", $data);
break; break;

View File

@ -68,7 +68,21 @@ class Sales extends CI_Controller
redirect("inventory/sales/list"); redirect("inventory/sales/list");
break; break;
case 'sales_register': 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); loadView("inventory/sales/register", $data);
break; break;
case 'details': case 'details':
@ -115,7 +129,6 @@ class Sales extends CI_Controller
$data['SalesRecords'] = $this->MSales->getSalesRecords(); $data['SalesRecords'] = $this->MSales->getSalesRecords();
loadView("inventory/sales/list", $data); loadView("inventory/sales/list", $data);
} }
} }

View File

@ -39,9 +39,9 @@ class MPurchases extends CI_Model
} }
return $PurchaseRecords; 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) { foreach ($PurchaseRecords as $PurchaseRecord) {
$PurchaseRecord->Details = $this->getPurchaseDetails($PurchaseRecord->purchase_id); $PurchaseRecord->Details = $this->getPurchaseDetails($PurchaseRecord->purchase_id);
$PurchaseRecord->TotalPurchase = $this->getTotalPurchaseAmount($PurchaseRecord->purchase_id); $PurchaseRecord->TotalPurchase = $this->getTotalPurchaseAmount($PurchaseRecord->purchase_id);

View File

@ -39,9 +39,9 @@ class MSales extends CI_Model
} }
return $SalesRecords; 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) { foreach ($SalesRecords as $SalesRecord) {
$SalesRecord->Details = $this->getSalesDetails($SalesRecord->sales_id); $SalesRecord->Details = $this->getSalesDetails($SalesRecord->sales_id);
$SalesRecord->totalsales = $this->getTotalSalesAmount($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'); $this->db->group_by('items_id');
$query = $this->db->get(); $query = $this->db->get();
$SalesRecords=$query->result(); $SalesRecords = $query->result();
foreach ($SalesRecords as $SalesRecord) { foreach ($SalesRecords as $SalesRecord) {
$SalesRecord->Item = $this->db->where("item_id", $SalesRecord->items_id)->get("tbl_items")->row(); $SalesRecord->Item = $this->db->where("item_id", $SalesRecord->items_id)->get("tbl_items")->row();
} }

View File

@ -7,21 +7,90 @@
<div class="card-header"> <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> --> <!-- <h5 class="m-0"><?php echo $pageTitle; ?> <?php showCreateButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/add", "Create New " . $pageTitle); ?></h5> -->
</div> </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"> <div class="card-body">
<?php $TableData = $this->db->query("select * from tbl_purchases where status=1")->result(); ?> <?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> <thead>
<tr> <tr>
<th width="3%" class="text-center"><?php myLang('S.N'); ?></th> <th width="3%" class="text-center"><?php myLang('S.N'); ?></th>
<th width="10%" class="col-1"><?php myLang('Date'); ?></th> <th width="10%" class="col-1"><?php myLang('Date'); ?></th>
<th class="table-col col-9"><?php myLang('Purchase Transaction'); ?></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> <td class="col-1 text-center"><b>Action</b></th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php $a = 0; $n=0; <?php $a = 0;
$n = 0;
foreach ($PurchaseRecords as $TableRow) : $a++; foreach ($PurchaseRecords as $TableRow) : $a++;
$id = $TableRow->purchase_id; ?> $id = $TableRow->purchase_id; ?>
<tr> <tr>
@ -50,3 +119,40 @@
</div> </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,10 +6,63 @@
<div class="card card-primary card-outline"> <div class="card card-primary card-outline">
<div class="card-header"> <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> <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>
<div class="card-body"> <div class="card-body">
<?php $TableData = $this->db->query("select * from tbl_sales where status=1")->result(); ?> <?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> <thead>
<tr> <tr>
<th class=" col-1 text-center"><?php myLang('ID'); ?></th> <th class=" col-1 text-center"><?php myLang('ID'); ?></th>
@ -22,14 +75,14 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
<?php $n=0 ; ?> <?php $n = 0; ?>
<?php foreach ($SalesRecords as $key=>$TableRow) : ?> <?php foreach ($SalesRecords as $key => $TableRow) : ?>
<tr> <tr>
<td class="text-center"><?php echo ++$n; ?></td> <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->sales_id; ?></td>
<td class="text-center"><?php echo ($TableRow->Details[$key]->Item->title) ?? ""; ?></td> <td class="text-center"><?php echo ($TableRow->Details[$key]->Item->title) ?? ""; ?></td>
<td><?php echo $TableRow->sales_date; ?></td> <td><?php echo $TableRow->sales_date; ?></td>
<td><?php echo (($this->myaccounts->getAccountDetails($TableRow->accounts_id)->account_name)?? ""); ?> <td><?php echo (($this->myaccounts->getAccountDetails($TableRow->accounts_id)->account_name) ?? ""); ?>
</td> </td>
<td><?php echo myCurrency($TableRow->totalsales); ?></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"); ?> <td class="text-center"><?php showDetailsButton($this->uri->segment(1) . "/" . $this->uri->segment(2) . "/details/$TableRow->sales_id"); ?>
@ -53,3 +106,40 @@
</div> </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-->