478 lines
14 KiB
PHP
Executable File
478 lines
14 KiB
PHP
Executable File
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
require APPPATH . '/libraries/BaseController.php';
|
|
require APPPATH . '/third_party/mpdf/mpdf.php';
|
|
/**
|
|
* Class : cash Book Controller (cash Book)
|
|
* User Class to control all user related operations.
|
|
* @author : Gandhimathi
|
|
* @version : 1.1
|
|
* @since : 13 Nov 2017
|
|
*/
|
|
class cashbook extends BaseController
|
|
{
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('cashbook_model');
|
|
$this->isLoggedIn();
|
|
$this->load->helper(array('form','url'));
|
|
$this->load->library('upload');
|
|
|
|
}
|
|
|
|
function incomeExpenseList()
|
|
{
|
|
|
|
$aid = $this->uri->segment(3);
|
|
$str = $this->uri->segment(4);
|
|
if(!empty($aid)){
|
|
|
|
if(!empty($str))
|
|
{
|
|
//echo "PDF";
|
|
$data['company'] = $this->cashbook_model->getCompany();
|
|
|
|
$data['data'] = $this->cashbook_model->getIncomeExpenseList($aid);
|
|
//$pic1 = $data['company'][0]->ProfilePic;
|
|
//echo $pic1;
|
|
//$pic = base_url().'uploads/images'.$pic1;
|
|
//echo $pic;
|
|
//die();
|
|
$totalamt = $data['data'][0]->total;
|
|
$data['amtinwords'] = $this->convertNumber($totalamt);
|
|
$mpdf=new mPDF('utf-8','A4-P',7, 10,10, 10, 3, 0, 0, 0);
|
|
$mpdf->SetHTMLHeader($HtmlHeading);
|
|
$html = $this->load->view('cashbookpdf',$data,true);
|
|
$mpdf->SetDisplayMode('fullpage');
|
|
$mpdf->setFooter($HTMLFooter . "Page {PAGENO} of {nb}");
|
|
$mpdf->list_indent_first_level = 1;
|
|
$mpdf->setAutoTopMargin = 'stretch';
|
|
$mpdf->setAutoBottomMargin = 'stretch';
|
|
$mpdf->WriteHTML($html);
|
|
$filename = "cashbook.pdf";
|
|
$mpdf->Output($filename,I);
|
|
}
|
|
else
|
|
{
|
|
|
|
$data['data'] = $this->cashbook_model->getIncomeExpenseList($aid);
|
|
//print_r($data['dropdownvalues']);die();
|
|
$this->global['pageTitle'] = 'Siddharth : Cash Book: View Income Expense ';
|
|
$this->loadViews("viewIndIncomeExpense", $this->global, $data , NULL);
|
|
|
|
}
|
|
|
|
}else{
|
|
$data['list'] = $this->cashbook_model->getIncomeExpenseList();
|
|
$this->global['pageTitle'] = 'Siddharth : Cash Book: Listing';
|
|
|
|
$this->loadViews("income_expense_list", $this->global, $data , NULL);
|
|
}
|
|
|
|
|
|
}
|
|
|
|
function addNewIncomeExpenseLoad()
|
|
{
|
|
|
|
$data['dropdownvalues'] = $this->cashbook_model->getAccounTypes();
|
|
//print_r($data['dropdownvalues']);die();
|
|
$this->global['pageTitle'] = 'Siddharth : Cash Book: Add New Income Expense ';
|
|
$this->loadViews("addnewIncomeExpense", $this->global, $data , NULL);
|
|
}
|
|
|
|
|
|
function addIncomeExpense()
|
|
{
|
|
//echo "welcome";
|
|
//die();
|
|
$accounttype = $this->input->post('myradio');
|
|
if($accounttype == 1)
|
|
{
|
|
$accounttype = 'RECEIPT';
|
|
}
|
|
else
|
|
{
|
|
$accounttype = 'PAYMENT';
|
|
}
|
|
$accountcode = $this->input->post('accode');
|
|
$date = $this->input->post('Date');
|
|
$date = date_create($date);//,'Y-m-d');
|
|
$date = date_format($date,'Y-m-d');
|
|
$towhome = $this->input->post('towhome');
|
|
|
|
$gsttoggle = $this->input->post('gsttoggle');
|
|
$invoiceno = null;
|
|
$merchantname = null;
|
|
$mergstno = null;
|
|
$hsn = null;
|
|
$beforegst = null;
|
|
$sgst = null;
|
|
$cgst = null;
|
|
$igst = null;
|
|
if(!empty($gsttoggle))
|
|
{
|
|
$invoiceno = $this->input->post('Invoiceno');
|
|
$merchantname = $this->input->post('merchant');
|
|
$mergstno = $this->input->post('Merchantgst');
|
|
$hsn = $this->input->post('hsn');
|
|
$beforegst = $this->input->post('valuebeforegST');
|
|
$sgst = $this->input->post('SGST');
|
|
$cgst = $this->input->post('CGST');
|
|
$igst = $this->input->post('IGST');
|
|
}
|
|
|
|
$totalamount = $this->input->post('totalamount');
|
|
|
|
$description = $this->input->post('description');
|
|
if(empty($description)){$description = 'NA';}
|
|
$document = null;
|
|
|
|
$fs = 0;
|
|
if(!empty($_FILES['myfile']['name']))
|
|
{
|
|
//echo "FILE AVAILABLE";
|
|
$config['file_name'] = $_FILES['myfile']['name'];
|
|
$config['upload_path'] = 'uploads/cashbook/';
|
|
$path = $config['upload_path'];
|
|
//$filename = $config['file_name'];
|
|
$document = $path.$filename;
|
|
//echo $document;
|
|
$fs = $this->uploadFile();
|
|
$document = $path.$fs;
|
|
|
|
}
|
|
$created_by = $this->session->userdata('userId');
|
|
$addincomexpense = array('type'=>$accounttype,'account_code'=>$accountcode,'date'=>$date,'towhom'=>$towhome,'invoice_no'=>$invoiceno,'merchant'=>$merchantname,'merchant_gst'=>$mergstno,'HSN'=>$hsn ,'value_before_gst'=>$beforegst,'sgst'=>$sgst,'cgst'=>$cgst,'igst'=>$igst,'total'=>$totalamount,'description'=>$description,'document'=>$document,'Created_By'=>$created_by);
|
|
$res = $this->cashbook_model->saveIncomeExpense($addincomexpense);
|
|
if( $res == 1 ){
|
|
echo "<script>alert('Saved Successfully!');window.location.href='ViewIncomeExpense';</script>";
|
|
}
|
|
|
|
}
|
|
|
|
|
|
function uploadFile()
|
|
{
|
|
|
|
//echo "INSIDE UPLOAFD";
|
|
|
|
//$this->load->library('upload')
|
|
$pathinfo = pathinfo($_FILES['myfile']['name']);
|
|
$config['upload_path'] = 'uploads/cashbook/';
|
|
$config['allowed_types'] = 'png|jpg|jpeg';
|
|
$config['file_name'] = $_FILES['myfile']['name'];
|
|
// $config['overwrite'] = true;
|
|
|
|
//Load upload library and initialize configuration
|
|
$this->load->library('upload',$config);
|
|
$this->upload->initialize($config);
|
|
|
|
|
|
if($this->upload->do_upload('myfile'))
|
|
{
|
|
$uploadData = $this->upload->data();
|
|
$uploadfilename = $uploadData['file_name'];
|
|
return $uploadfilename;
|
|
|
|
}
|
|
else
|
|
{
|
|
$error = array('error' => $this->upload->display_errors());
|
|
$uploadfilename = '';
|
|
print_r($error);
|
|
return 0;
|
|
}
|
|
|
|
}
|
|
|
|
function viewIE()
|
|
{
|
|
|
|
$aid = $this->uri->segment(3);
|
|
|
|
$data['data'] = $this->cashbook_model->getAccounutInfo();
|
|
//print_r($data['dropdownvalues']);die();
|
|
$this->global['pageTitle'] = 'Siddharth : Cash Book: View Income Expense ';
|
|
$this->loadViews("viewIndIncomeExpense", $this->global, $data , NULL);
|
|
|
|
}
|
|
|
|
public function index()
|
|
{
|
|
$this->global['pageTitle'] = 'Siddharth : Cashbook Details';
|
|
$this->loadViews("cashbooklisting", $this->global, NULL , NULL);
|
|
|
|
}
|
|
|
|
public function cashbookList()
|
|
{
|
|
|
|
|
|
$this->load->model('cashbook_model');
|
|
|
|
$data['cashbook'] = $this->cashbook_model->Selectcash();
|
|
|
|
$this->global['pageTitle'] = 'Siddharth : Cashbook Listing';
|
|
|
|
$this->loadViews("cashbooklisting", $this->global, $data, NULL);
|
|
|
|
}
|
|
|
|
public function cashbookdtl()
|
|
{
|
|
|
|
|
|
$id = $this->input->post('id');
|
|
$tablevalue = json_decode($id,true);
|
|
//print_r($tablevalue);
|
|
foreach($tablevalue as $tv)
|
|
{
|
|
if(!empty($tv['AccountCodeType'])){
|
|
$acc_type = $tv['AccountCodeType'];
|
|
$acc_code = $tv['AccountCode'];
|
|
$acc_name = $tv['AccountName'];
|
|
$acc_desc = $tv['Description'];
|
|
$acc_state = $tv['Status'];
|
|
if(strtoupper($acc_state) == 'YES')
|
|
{
|
|
$acc_status = 1;
|
|
}
|
|
else{
|
|
$acc_status = 0;
|
|
}
|
|
|
|
|
|
$dt = new DateTime('now', new DateTimeZone('Asia/Kolkata'));
|
|
$acc_createddt = $dt->format('Y-m-d H:i:s');
|
|
|
|
$cashbookdatas = array('type'=>$acc_type,'code'=>$acc_code,'name'=>$acc_name,'description'=>$acc_desc,'status'=>$acc_status,'created_on'=>$acc_createddt);
|
|
//print_r($cashbookdatas);
|
|
$result = $this->cashbook_model->Cashbook($cashbookdatas);
|
|
}
|
|
}
|
|
|
|
|
|
//redirect('cashbook/cashbookList','refresh');
|
|
echo "Successfully Saved!";
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
public function editcashbook($sid)
|
|
{
|
|
|
|
if($sid == '')
|
|
{
|
|
$cash = $_GET['sid'];
|
|
}
|
|
else
|
|
{
|
|
$cash = $sid;
|
|
}
|
|
|
|
|
|
$this->load->model('cashbook_model');
|
|
|
|
$data['DepDetails'] = $this->cashbook_model->viewdepartment($cash);
|
|
//$data['deletefile'] = $this->cashbook-model->deletefile($cash);
|
|
$data['dropdownvalues'] = $this->cashbook_model->getAccounTypes();
|
|
//print_r( $data['DepDetails']);die();
|
|
$this->global['pageTitle'] = 'Siddharth : Edit Cashbook';
|
|
$this->loadViews("editincomeexpenses", $this->global,$data, NULL);
|
|
|
|
}
|
|
public function deletefile()
|
|
{
|
|
$cashfile = $this->input->post('id');
|
|
$cashid = $this->input->post('ide');
|
|
//echo 'dsmkjsn';
|
|
//echo $cashid;
|
|
|
|
//echo $cashfile;
|
|
//die();
|
|
//$this->load->model('cashbook_model');
|
|
$filedata= $this->cashbook_model->deletefile($cashid);
|
|
echo $filedata;
|
|
//$this->global['pageTitle'] = 'Siddharth : Edit Cashbook';
|
|
//$this->loadViews("income_expense_list", $this->global,$data, NULL);
|
|
|
|
}
|
|
function updateExpense()
|
|
{
|
|
$id1=$this->input->post('id1');
|
|
$myradio1= $this->input->post('myradio');
|
|
$option='';
|
|
if($myradio1==1)
|
|
{
|
|
$option=RECEIPT;
|
|
}
|
|
else
|
|
{
|
|
$option=PAYMENT;
|
|
}
|
|
//echo $option;die();
|
|
$ans1 = $this->input->post('ans');
|
|
$Date1 = $this->input->post('Date');
|
|
//echo $Date1;
|
|
$date = date_create($Date1);//,'Y-m-d');
|
|
$date = date_format($date,'Y-m-d');
|
|
//echo $date;
|
|
//$Date1 = $this->input->post('Date');
|
|
$accountcode1 = $this->input->post('accode');
|
|
//echo $accountcode1;die();
|
|
$towhome1 = $this->input->post('towhome');
|
|
$Invoiceno1 = $this->input->post('Invoiceno');
|
|
$merchant1 = $this->input->post('merchant');
|
|
$Merchantgst1 = $this->input->post('Merchantgst');
|
|
$hsn1 = $this->input->post('hsn');
|
|
$valuebeforegST1 = $this->input->post('valuebeforegST');
|
|
$SGST1 = $this->input->post('SGST');
|
|
$CGST1 = $this->input->post('CGST');
|
|
$IGST1 = $this->input->post('IGST');
|
|
$totalamount1 = $this->input->post('totalamount');
|
|
$description1 = $this->input->post('description');
|
|
$deleteflag = $this->input->post('deleteflag');
|
|
$oldfile = $this->input->post('oldfile');
|
|
$document =null;
|
|
|
|
//$document1=$this->input->post('myfile');
|
|
$fs = 0;
|
|
if(!empty($_FILES['myfile']['name']))
|
|
{
|
|
//echo "FILE AVAILABLE";
|
|
$config['file_name'] = $_FILES['myfile']['name'];
|
|
$config['upload_path'] = 'uploads/cashbook/';
|
|
$path = $config['upload_path'];
|
|
//$filename = $config['file_name'];
|
|
//$document = $path.$filename;
|
|
//echo $document;
|
|
$fs = $this->uploadFile();
|
|
$document = $path.$fs;
|
|
|
|
|
|
}
|
|
else
|
|
{
|
|
if($deleteflag == 0)
|
|
{
|
|
$document = $oldfile;
|
|
}
|
|
else if($deleteflag == 1)
|
|
{
|
|
$document = null;
|
|
}
|
|
}
|
|
$updateaccount = array('type'=>$option,'account_code'=>$accountcode1,'date'=>$date,'towhom'=>$towhome1,'invoice_no'=>$Invoiceno1,'merchant'=>$merchant1,'merchant_gst'=>$Merchantgst1,'HSN'=>$hsn1,'value_before_gst'=>$valuebeforegST1,'sgst'=>$SGST1,'cgst'=>$CGST1,'igst'=>$IGST1,'total'=>$totalamount1,'description'=>$description1,'document'=>$document);
|
|
//print_r($updateaccount);die();
|
|
$res = $this->cashbook_model->updatedepartment($updateaccount,$id1);
|
|
|
|
//if( $res == 1 ){
|
|
echo "<script>alert('Saved Successfully!');window.location.href='ViewIncomeExpense';</script>";
|
|
//}
|
|
}
|
|
|
|
|
|
|
|
public function convertNumber($amt){
|
|
//echo $amt;die();
|
|
$ShowPaise='0';
|
|
$totalAmt=explode(".",$amt);
|
|
|
|
$number = $totalAmt[0];
|
|
$no = $number;
|
|
|
|
if(!empty($totalAmt[1]) && $totalAmt[1]!=0){
|
|
$point = $totalAmt[1];
|
|
$ShowPaise='1';
|
|
}
|
|
else{
|
|
$point=0;
|
|
$ShowPaise='0';
|
|
}
|
|
|
|
|
|
$hundred = null;
|
|
$digits_1 = strlen($no);
|
|
|
|
$i = 0;
|
|
$str = array();
|
|
$words = array('0' => '', '1' => 'One', '2' => 'Two',
|
|
'3' => 'three', '4' => 'Four', '5' => 'Five', '6' => 'Six',
|
|
'7' => 'seven', '8' => 'eight', '9' => 'nine',
|
|
'10' => 'ten', '11' => 'eleven', '12' => 'twelve',
|
|
'13' => 'thirteen', '14' => 'fourteen',
|
|
'15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
|
|
'18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',
|
|
'30' => 'thirty', '40' => 'forty', '50' => 'fifty',
|
|
'60' => 'sixty', '70' => 'seventy',
|
|
'80' => 'eighty', '90' => 'ninety','06'=>'Zero Six','01'=>'Zero One','02'=>'Zero Two'
|
|
,'03'=>'Zero Three','04'=>'Zero Four','05'=>'Zero Five','07'=>'Zero Seven','08'=>'Zero Eight','09'=>'Zero Nine');
|
|
$words1 = array('2' => 'twenty',
|
|
'3' => 'thirty', '4' => 'fourty',
|
|
'5' => 'fifty', '6' => 'sixty', '7' => 'seventy',
|
|
'8' => 'eighty', '9' =>'ninty');
|
|
$words12 = array('11' => 'eleven',
|
|
'12' => 'twelve', '13' => 'thirteen', '14' => 'fourteen',
|
|
'15' => 'fifteen', '16' => 'sixteen', '17' => 'seventeen',
|
|
'18' => 'eighteen', '19' =>'nineteen', '20' => 'twenty',);
|
|
$digits = array('', 'hundred', 'thousand', 'lakh', 'crore');
|
|
while ($i < $digits_1) {
|
|
$divider = ($i == 2) ? 10 : 100;
|
|
$number = floor($no % $divider);
|
|
$no = floor($no / $divider);
|
|
$i += ($divider == 10) ? 1 : 2;
|
|
if ($number) {
|
|
$plural = (($counter = count($str)) && $number > 1) ? 's' : null;
|
|
//print_r($plural);
|
|
$hundred = ($counter == 1 && $str[0]) ? ' and ' : null;
|
|
//print_r($hundred);
|
|
$str [] = ($number < 21) ? $words[$number] .
|
|
" " . $digits[$counter] . $plural . " " . $hundred
|
|
:
|
|
$words[floor($number / 10) * 10]
|
|
. " " . $words[$number % 10] . " "
|
|
. $digits[$counter] . $plural . " " . $hundred;
|
|
} else $str[] = null;
|
|
}
|
|
$str = array_reverse($str);
|
|
$result = implode('', $str);
|
|
if($point>=1 && $point<=10)
|
|
{
|
|
$points = ($point) ?
|
|
" " . $words[$point] : " ";
|
|
}
|
|
else if($point>=11 && $point<=20)
|
|
{
|
|
$points = ($point) ?
|
|
" " . $words12[$point] : " ";
|
|
}
|
|
else
|
|
{
|
|
$points = ($point) ?
|
|
" " . $words1[$point / 10] . " " .
|
|
$words[$point = $point % 10] : '';
|
|
}
|
|
|
|
if($ShowPaise=='0'){
|
|
|
|
$amountInWords = "Rupees " . $result." Only";
|
|
}
|
|
else{
|
|
|
|
$amountInWords = "Rupees " . $result ." Paise ". $points." Only";
|
|
}
|
|
|
|
|
|
return $amountInWords;
|
|
}
|
|
|
|
}
|
|
?>
|