load->model('cashbook_model'); $this->isLoggedIn(); $this->load->helper(array('form','url')); $this->load->library('upload'); $this->CompanyName = $this->global['CompanyName']; } /** * To list income expense details */ function incomeExpenseList() { $aid = $this->uri->segment(3); $str = $this->uri->segment(4); if(!empty($aid)){ if(!empty($str)) { $data['company'] = $this->cashbook_model->getCompany(); $data['data'] = $this->cashbook_model->getIncomeExpenseList($aid); $data['PaymentDetails'] = $this->cashbook_model->viewpaymentdetails($aid); $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); $data['PaymentDetails'] = $this->cashbook_model->viewpaymentdetails($aid); //$this->global['pageTitle'] = 'Resico : Cash Book: View Income Expense '; $this->global['pageTitle'] = $this->CompanyName.' : Cash Book - View Income Expense '; $this->loadViews("viewIndIncomeExpense", $this->global, $data , NULL); } } else{ //$data['list'] = $this->cashbook_model->getIncomeExpenseList(); //$data['list'] = $this->cashbook_model->getreceiptpaymentlist(); //$this->global['pageTitle'] = 'Resico : Cash Book: Listing'; $this->global['pageTitle'] = $this->CompanyName.': Receipt and Payment Details'; if ($this->input->post('btn_submit')) { $fromdt = $this->input->post('from_date'); $todt = $this->input->post('to_date'); $ab=$this->input->post('financialyear'); $fromyear=substr($ab,0,-5); $toyear=substr($ab,5,5); $data['finyear']=$this->cashbook_model->finyear(); $data['list'] = $this->cashbook_model->getIncomeExpense($fromyear,$toyear,$fromdt,$todt); } else{ if (date('m') <= 3) { $preyear = (date('Y')-1); $currentyear = date('Y'); } else { $preyear = date('Y') ; $currentyear = (date('Y') + 1); } $data['list'] = $this->cashbook_model->getIncomeExpense($preyear,$currentyear); $data['finyear']=$this->cashbook_model->finyear(); } $this->loadViews("income_expense_list", $this->global, $data , NULL); } } /** * To load add incomeexpense screen */ function addNewIncomeExpenseLoad() { $data['dropdownvalues'] = $this->cashbook_model->getAccounTypes(); //$this->global['pageTitle'] = 'Resico : Cash Book: Add New Income Expense '; $this->global['pageTitle'] = $this->CompanyName.': Cash Book: Add New Income Expense '; $this->loadViews("addnewIncomeExpense", $this->global, $data , NULL); } /** * To store added incomeexpense datas */ //function addIncomeExpense() function addReceipt() { $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; $subdescription = 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'])) { $config['file_name'] = $_FILES['myfile']['name']; $config['upload_path'] = 'uploads/cashbook/'; $path = $config['upload_path']; $document = $path.$filename; $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,'subdescription'=>$subdescription); $res = $this->cashbook_model->saveIncomeExpense($addincomexpense); if( $res >= 1 ){ echo ""; } } /** * To store added Cashbook's Payment datas */ function addPayment() { $count = $this->input->post('hidecounter'); $constantcount = $this->input->post('hideconstant'); $accounttype = 'PAYMENT'; $date = $this->input->post('PaymentDate'); $date = date_create($date);//,'Y-m-d'); $date = date_format($date,'Y-m-d'); $paidto = $this->input->post('PaymentPaidto'); $vouchercode = $this->input->post('Paymentvouchercode'); //echo $count.$consantcount; //$gsttoggle = $this->input->post('gsttoggle'); //$invoiceno = null; $merchantname = null; $mergstno = null; $hsn = null; $beforegst = null; $sgst = null; $cgst = null; $igst = null; $merchantname = $this->input->post('Paymentmerchant'); $mergstno = $this->input->post('PaymentMerchantgst'); $hsn = $this->input->post('Paymenthsn'); $beforegst = $this->input->post('PaymentvaluebeforegST'); $sgst = $this->input->post('PaymentSGST'); $cgst = $this->input->post('PaymentCGST'); $igst = $this->input->post('PaymentIGST'); $totalamount = $this->input->post('Paymenttotalamount'); $description = $this->input->post('Paymentdescription'); if(empty($description)){$description = 'NA';} $document = null; $fs = 0; if(!empty($_FILES['myfile']['name'])) { $config['file_name'] = $_FILES['myfile']['name']; $config['upload_path'] = 'uploads/cashbook/'; $path = $config['upload_path']; $document = $path.$filename; $fs = $this->uploadFile(); $document = $path.$fs; } $created_by = $this->session->userdata('userId'); if($count == 1) { $array = $this->input->post('mydata1'); if(!empty($array)){ $array[] = $this->input->post($varname); $index = 0; foreach($array as $key=>$value){ $index++; if($index == 1){ $Paymentaccode = $value; } if($index == 2){ $subdescription = $value; } }} $addPayments = array('type'=>$accounttype,'account_code'=>$Paymentaccode,'date'=>$date,'towhom'=>$paidto,'invoice_no'=>$vouchercode,'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,'paymentsubdesc'=>$subdescription); $res = $this->cashbook_model->saveIncomeExpense($addPayments); } else { $accountcode = '999'; $subdescription = 'Multiple'; $addPayments = array('type'=>$accounttype,'account_code'=>$accountcode,'date'=>$date,'towhom'=>$paidto,'invoice_no'=>$vouchercode,'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,'paymentsubdesc'=>$subdescription); $res = $this->cashbook_model->saveIncomeExpense($addPayments); $Paymentaccode = ''; $subdescription = ''; $Paymentamount = ''; for($i=1;$i<=$constantcount;$i++){ $varname = 'mydata'.$i; //alert($varname); $temp = $this->input->post($varname); if(!empty($temp)){ $g[] = $this->input->post($varname); //echo "sd"; //print_r($g); //die(); } else{} } foreach($g as $arr){ // $Paymentaccode = $arr->Paymentaccode; // $subdescription = $arr->subdescription; // $Paymentamount = $arr->Paymentamount; $index = 0; foreach($arr as $key=>$value){ $index++; // echo "*************"; // echo $key; // echo $value; // echo "*************"; if($index == 1){ $Paymentaccode = $value; } if($index == 2){ $subdescription = $value; } if($index == 3){ $Paymentamount = $value; } } //insert; $addPaymentDetails = array('Payment_id'=>$res,'Account_code'=>$Paymentaccode,'Account_description'=>$subdescription,'Amount'=>$Paymentamount); //print_r($addPaymentschild); //$child = $this->cashbook_model->paymentdetails($addPaymentschild); $child = $this->cashbook_model->addpaymentdetails($addPaymentDetails); //addupdatepaymentdetails($addPaymentschild,$res); //echo $child; //echo $paymentcode; } }//new else if( $res >= 1 ){ echo ""; } } /** * To store Cashbook revalant file and images */ function uploadFile() { $pathinfo = pathinfo($_FILES['myfile']['name']); $config['upload_path'] = 'uploads/cashbook/'; $config['allowed_types'] = 'png|jpg|jpeg|pdf'; $config['file_name'] = $_FILES['myfile']['name']; //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; } } /** * To load view Income Expense screen */ function viewIE() { $aid = $this->uri->segment(3); $data['data'] = $this->cashbook_model->getAccounutInfo(); //$this->global['pageTitle'] = 'Resico : Cash Book: View Income Expense '; $this->global['pageTitle'] = $this->CompanyName.' : Cash Book: View Income Expense '; $this->loadViews("viewIndIncomeExpense", $this->global, $data , NULL); } /** * Index Page for this controller(default function of the class) */ public function index() { //$this->global['pageTitle'] = 'Resico : Cashbook Details'; $this->global['pageTitle'] = $this->CompanyName.' : 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'] = 'Resico : Cashbook Listing'; $this->global['pageTitle'] = $this->CompanyName.' : Cashbook Listing'; $this->loadViews("cashbooklisting", $this->global, $data, NULL); } public function cashbookdtl() { $id = $this->input->post('id'); $tablevalue = json_decode($id,true); 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); $result = $this->cashbook_model->Cashbook($cashbookdatas); } } echo "Successfully Saved!"; } /** * For edit cashbook screen */ public function editcashbook($sid) { if($sid == '') { $cash = $_GET['sid']; } else { $cash = $sid; } $this->load->model('cashbook_model'); /** this array for single entry both recepit and payment datas*/ $data['RecepitPayment'] = $this->cashbook_model->viewdepartment($cash); /** this array for paymentmaster mutilpe datas */ $data['PaymentMultiple'] = $this->cashbook_model->viewpaymentmaster($cash); /** this array for paymentchild datas */ $data['PaymentDetails'] = $this->cashbook_model->viewpaymentdetails($cash); /** this array for dropdown value(account name)*/ $data['dropdownvalues'] = $this->cashbook_model->getAccounTypes(); //$this->global['pageTitle'] = 'Resico : Edit Cashbook'; $this->global['pageTitle'] = $this->CompanyName.' : Edit Cashbook'; $this->loadViews("editincomeexpenses", $this->global,$data, NULL); } public function deletefile() { $cashfile = $this->input->post('id'); $cashid = $this->input->post('ide'); $filedata= $this->cashbook_model->deletefile($cashid,$cashfile); echo $filedata; } function Removepaymentdetails(){ $id = $this->input->post('id'); $deletedata = $this->cashbook_model->deletepaymentdetails($id); echo $deletedata; } function updateReceipt() { $id1=$this->input->post('id1'); // $myradio1= $this->input->post('myradio'); // $option=''; // if($myradio1==1) // { $option=RECEIPT; // } // else // { // $option=PAYMENT; // } $ans1 = $this->input->post('ans'); $Date1 = $this->input->post('Date'); $date = date_create($Date1);//,'Y-m-d'); $date = date_format($date,'Y-m-d'); $accountcode1 = $this->input->post('accode'); $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; $fs = 0; if(!empty($_FILES['myfile']['name'])) { $config['file_name'] = $_FILES['myfile']['name']; $config['upload_path'] = 'uploads/cashbook/'; $path = $config['upload_path']; $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); $res = $this->cashbook_model->updatedepartment($updateaccount,$id1); echo ""; } function updatePayment() { $id1=$this->input->post('id1'); $count = $this->input->post('hidecounter');//hide value $constantcount = $this->input->post('hideconstant');//hide value $option=PAYMENT; $ans1 = $this->input->post('ans'); $Date1 = $this->input->post('PaymentDate'); $date = date_create($Date1);//,'Y-m-d'); $date = date_format($date,'Y-m-d'); $towhome1 = $this->input->post('PaymentPaidto'); $Invoiceno1 = $this->input->post('Paymentvouchercode'); $merchant1 = $this->input->post('Paymentmerchant'); $Merchantgst1 = $this->input->post('PaymentMerchantgst'); $hsn1 = $this->input->post('Paymenthsn'); $valuebeforegST1 = $this->input->post('PaymentvaluebeforegST'); $SGST1 = $this->input->post('PaymentSGST'); $CGST1 = $this->input->post('PaymentCGST'); $IGST1 = $this->input->post('PaymentIGST'); $totalamount1 = $this->input->post('Paymenttotalamount'); $description1 = $this->input->post('Paymentdescription'); $deleteflag = $this->input->post('deleteflag'); $oldfile = $this->input->post('oldfile'); $document =null; $fs = 0; if(!empty($_FILES['myfile']['name'])) { $config['file_name'] = $_FILES['myfile']['name']; $config['upload_path'] = 'uploads/cashbook/'; $path = $config['upload_path']; $fs = $this->uploadFile(); $document = $path.$fs; } else { if($deleteflag == 0) { $document = $oldfile; } else if($deleteflag == 1) { $document = null; } } if($count == 1) { $array = $this->input->post('mydata1'); if(!empty($array)){ $array[] = $this->input->post($varname); $index = 0; foreach($array as $key=>$value){ $index++; if($index == 1){ $Paymentaccode = $value; } if($index == 2){ $subdescription = $value; } }} $UpdatePayment = array('type'=>$option,'account_code'=>$Paymentaccode,'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,'paymentsubdesc'=>$subdescription); $res = $this->cashbook_model->updatepaymentmaster($UpdatePayment,$id1); } else { $accountcode = '999'; $subdescription0 = 'Multiple'; $UpdatePayment = array('type'=>$option,'account_code'=>$accountcode,'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,'paymentsubdesc'=>$subdescription0); $res = $this->cashbook_model->updatepaymentmaster($UpdatePayment,$id1); for($i=1;$i<=$constantcount;$i++){ $varname = 'mydata'.$i; $temp = $this->input->post($varname); if(!empty($temp)){ $g[] = $this->input->post($varname); } else{} } //print_r($g); echo "
****************************"; foreach($g as $arr){ $insert = count($arr); //echo $insert; if($insert == 3){ //print_r($arr); echo "
*********THREE insert************"; $index = 0; foreach($arr as $key=>$value){ $index++; // echo "*************"; // echo $key; // echo $value; // echo "*************"; if($index == 1){ $Payment_accode = $value; } if($index == 2){ $sub_description = $value; } if($index == 3){ $Payment_amount = $value; } } if($Payment_accode != -1) { $addPaymentsdetails = array('Payment_id'=>$id1,'Account_code'=>$Payment_accode,'Account_description'=>$sub_description,'Amount'=>$Payment_amount); $child = $this->cashbook_model->addpaymentdetails($addPaymentsdetails); } } else if($insert == 4){ // print_r($arr); echo "
*********FOUR update************"; $index = 0; foreach($arr as $key=>$value){ $index++; if($index == 1){ $Paymentaccode = $value; } if($index == 2){ $subdescription = $value; } if($index == 3){ $Paymentamount = $value; } if($index == 4){ $hidekey = $value; } } $UpdatePaymentsdetails = array('Payment_id'=>$id1,'Account_code'=>$Paymentaccode,'Account_description'=>$subdescription,'Amount'=>$Paymentamount); $child = $this->cashbook_model->updatepaymentdetails($UpdatePaymentsdetails,$hidekey); } } } echo ""; } /** * To covert number into words */ public function convertNumber($amt){ $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' => 'fourty', '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' =>'ninety'); $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; $hundred = ($counter == 1 && $str[0]) ? ' and ' : null; $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; } /** *To get Payment Datas form ajax */ function ViewPaymentDetails() { $paymentid= $this->input->post('id'); $data = $this->cashbook_model->viewpaymentdetails($paymentid); echo json_encode($data); } } ?>