BBnepal-Accounts/account/application/views/accounts/importvouchers.php
Sampanna Rimal 9cd05ef3cb commitall
2024-07-10 18:28:19 +05:45

122 lines
5.4 KiB
PHP

<div class="content-wrapper">
<div class="content">
<div class="container-fluid">
<div class="row">
<div class="col">
<div class="card card-primary card-outline">
<div class="card-header">
<h5 class="m-0"><?php echo $pageTitle; ?> </h5>
</div>
<div class="card-body">
<form method=POST action="" enctype="multipart/form-data" name="tbl_vouchers">
<div class="row">
<!--COL START-->
<div class="col">
<div class="form-group"> <label for="import_type">Voucher List</label>
<select class="form-control" id="import_type" value="" name="import_type">
<option value="Groups">Groups</option>
<option value="Categories">Categories</option>
<option value="Accounts">Accounts</option>
<option value="Vouchers">Vouchers</option>
<option value="VoucherDetails">Voucher Details</option>
<option value="All">All</option>
</select>
</div>
</div>
<div class="col">
<div class="form-group"> <label for="voucher_list">Voucher List</label>
<input type="file" class="form-control" id="voucher_list" value="" name="voucher_list">
</div>
</div>
<!--COL END-->
</div>
</div>
<button class="btn btn-primary" type="submit" name="submit">Save</button>
</form>
<?php if(isset($importedData)) { ?>
<?php $importedVouchers=array(); ?>
<table class="table table-striped table-responsive dataTable">
<thead>
<?php $h = $importedData[0];
unset($importedData[0]); ?>
<tr>
<?php $i=0; foreach ($h as $c) : ?>
<th><?php echo $c." ($i)"; $i++; ?>
</th>
<?php endforeach; ?>
</tr>
</thead>
<tbody>
<?php foreach ($importedData as $r) : ?>
<?php $importedVouchers=addVouchers($r,$importedVouchers); ?>
<tr>
<?php foreach ($r as $c) : ?>
<td><?php echo $c; ?></td>
<?php endforeach; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php
$this->db->query("truncate table tbl_vouchers");
foreach($importedVouchers as $importedVoucher):
$this->db->insert("tbl_vouchers",$importedVoucher);
endforeach;
?>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<?php
function addVouchers($importedLine, $importedVouchers)
{
/*
[0] => voucher_id
[1] => voucher_no
[2] => voucher_ref
[3] => voucher_date
[4] => voucher_state
[5] => voucher_type
[6] => fiscalyear_id
[7] => branch_id
[8] => created_by
[9] => created_on
[10] => remarks
[11] => status
*/
$dbVoucher=new stdClass;
$dbVoucher->voucher_id=$importedLine[1];
$dbVoucher->voucher_no=$importedLine[2];
$dbVoucher->voucher_ref=$importedLine[3];
$dbVoucher->voucher_date=dbDate($importedLine[4]);
$dbVoucher->voucher_state=$importedLine[5];
$dbVoucher->voucher_type=$importedLine[6];
$dbVoucher->fiscalyear_id=$_SESSION['FiscalYearID'];
$dbVoucher->branch_id=$_SESSION['BranchID'];
$dbVoucher->created_by=$importedLine[8];
$dbVoucher->created_on=dbDate($importedLine[7]);
$dbVoucher->remarks=$importedLine[11];
$dbVoucher->status=$importedLine[12];
if(!in_array($dbVoucher,$importedVouchers)) $importedVouchers[]=$dbVoucher;
return $importedVouchers;
}
?>