load->model('mdl_payments'); $this->load->model('invoices/mdl_invoices'); } /** * @param int $page */ public function index($page = 0) { $this->mdl_payments->paginate(site_url('payments/index'), $page); $payments = $this->mdl_payments->result(); //print_r($payments); $this->layout->set( array( 'payments' => $payments, 'filter_display' => true, 'filter_placeholder' => trans('filter_payments'), 'filter_method' => 'filter_payments' ) ); $this->layout->buffer('content', 'payments/index'); $this->layout->render(); } /** * @param null $id */ public function form($id = null) { if ($this->input->post('btn_cancel')) { redirect('payments'); } if ($this->mdl_payments->run_validation()) { $id = $this->mdl_payments->save($id); $this->load->model('custom_fields/mdl_payment_custom'); $this->mdl_payment_custom->save_custom($id, $this->input->post('custom')); redirect('payments'); } if (!$this->input->post('btn_submit')) { $prep_form = $this->mdl_payments->prep_form($id); if ($id and !$prep_form) { show_404(); } $this->load->model('custom_fields/mdl_payment_custom'); $this->load->model('custom_values/mdl_custom_values'); $payment_custom = $this->mdl_payment_custom->where('payment_id', $id)->get(); if ($payment_custom->num_rows()) { $payment_custom = $payment_custom->row(); unset($payment_custom->payment_id, $payment_custom->payment_custom_id); foreach ($payment_custom as $key => $val) { $this->mdl_payments->set_form_value('custom[' . $key . ']', $val); } } } else { if ($this->input->post('custom')) { foreach ($this->input->post('custom') as $key => $val) { $this->mdl_payments->set_form_value('custom[' . $key . ']', $val); } } } $this->load->helper('custom_values'); $this->load->model('invoices/mdl_invoices'); $this->load->model('payment_methods/mdl_payment_methods'); $this->load->model('custom_fields/mdl_custom_fields'); $this->load->model('custom_values/mdl_custom_values'); $open_invoices = $this->mdl_invoices ->where('ip_invoice_amounts.invoice_balance >', 0) ->or_where('ip_invoice_amounts.invoice_balance <', 0) ->get()->result(); $Client_details= $this->mdl_invoices->GetClient_Details(); // print_r($open_invoices); $custom_fields = $this->mdl_custom_fields->by_table('ip_payment_custom')->get()->result(); $custom_values = []; foreach ($custom_fields as $custom_field) { if (in_array($custom_field->custom_field_type, $this->mdl_custom_values->custom_value_fields())) { $values = $this->mdl_custom_values->get_by_fid($custom_field->custom_field_id)->result(); $custom_values[$custom_field->custom_field_id] = $values; } } $fields = $this->mdl_payment_custom->get_by_payid($id); //$viewpayment=$this->mdl_payments->Get_PaymentDetails($id); //print_r($viewpayment); foreach ($custom_fields as $cfield) { foreach ($fields as $fvalue) { if ($fvalue->payment_custom_fieldid == $cfield->custom_field_id) { // TODO: Hackish, may need a better optimization $this->mdl_payments->set_form_value( 'custom[' . $cfield->custom_field_id . ']', $fvalue->payment_custom_fieldvalue ); break; } } } $amounts = array(); $invoice_payment_methods = array(); //print_r($amounts); foreach ($open_invoices as $open_invoice) { $amounts['invoice' . $open_invoice->invoice_id] = format_amount($open_invoice->invoice_balance); $invoice_payment_methods['invoice' . $open_invoice->invoice_id] = $open_invoice->payment_method; } $lastrecid= $this->mdl_payments->GetReceiptCount(); $rid=''; foreach($lastrecid as $rid) { $rid=$rid->rcount; } if($rid<=0) { $lastpayid='REC1'; } else { $lastrid=$this->mdl_payments->GetReceiptid(); foreach($lastrid as $r) { $ri=$r->lrid; } } $rid=(explode("C",$ri)); //print_r($rid); $this->layout->set( array( 'payment_id' => $id, 'payment_methods' => $this->mdl_payment_methods->get()->result(), 'open_invoices' => $open_invoices, 'custom_fields' => $custom_fields, 'custom_values' => $custom_values, 'amounts' => json_encode($amounts), 'client_name' => $Client_details, 'viewpayment'=>$this->mdl_payments->Get_PaymentDetails($id), 'PaymentLineDetails'=> $this->mdl_payments->Get_InvoicelistPayment($id), 'lastpayid'=> $this->mdl_payments->Get_LastPaymentid(), 'lastrecid'=> $this->mdl_payments->GetReceiptCount(), 'lastrid'=>$this->mdl_payments->GetReceiptid(), // 'amountid' => json_encode($amountid), 'invoice_payment_methods' => json_encode($invoice_payment_methods) ) ); if ($id) { $this->layout->set('payment', $this->mdl_payments->where('ip_payments.payment_id', $id)->get()->row()); } $this->layout->buffer('content', 'payments/form'); $this->layout->render(); } /** * @param $id */ public function delete($id) { $this->mdl_payments->delete($id); redirect('payments'); } public function Get_Invoice() { $client_id=$this->input->post('id'); $from_date=$this->input->post('from_date'); $to_date=$this->input->post('to_date'); $fdate=date("Y-m-d", strtotime($from_date) ); $tdate=date("Y-m-d",strtotime($to_date)); $Invoice_list = $this->mdl_payments->Get_Invoicelist($client_id,$fdate,$tdate); $obj=json_encode($Invoice_list); //die(json_encode(array('InvDetail' =>$Invoice_list))); echo $obj; } public function Invoice_Clearence() { $all=$this->input->post('al'); $jj=$this->input->post('j'); $RowCount=$this->input->post('RowCount'); // echo $RowCount; $invoice_id=$this->input->post('Inid'); $dt = new DateTime('now', new DateTimeZone('Asia/Kolkata')); $payment_date = $dt->format('Y-m-d'); //$payment_amount=$this->input->post('Payment'); $totalPayment=$this->input->post('TotPay'); $paymentmethod=$this->input->post('paymentmethod'); $note=$this->input->post('paynote'); $balance=$this->input->post('Balance'); $payment_amount = $this->input->post('inv_amount'); //$PayBalance=$balance - $payment_amount; $receiptno= $this->input->post('pid'); $totalamt= $this->input->post('totalamt'); $EarlierPaid= $this->mdl_payments->GetEarlyPayment($invoice_id); $PaidAmount=0; foreach($EarlierPaid as $Pay) { $PaidAmount= $Pay->invoice_paid; } $InvId_check= $this->mdl_payments->CheckInvId($invoice_id); $payment_amount1= $PaidAmount + $payment_amount; $PayBalance= $totalPayment - $payment_amount1; //echo $i; if($PayBalance>0) { $ip_status=2; } else { $ip_status=4; } $balance_array=array('invoice_balance'=>$PayBalance,'invoice_paid'=>$payment_amount1); $inv_balance=$this->mdl_payments->Save_Balance($balance_array,$invoice_id); $invstatusarray=array('invoice_status_id'=>$ip_status,'payment_method'=>$paymentmethod); $statusupdation=$this->mdl_payments->Save_invstatus($invstatusarray,$invoice_id); $payt=array('payment_method_id'=>$paymentmethod,'payment_date'=>$payment_date); $paymenttable=array('invoice_id'=>$invoice_id,'payment_method_id'=>$paymentmethod,'payment_date'=>$payment_date,'payment_amount'=>$payment_amount,'payment_note'=>$note,'receipt_no'=>$receiptno,'total_payment'=>$totalamt); // if(count($InvId_check)==0) // { $paytable=$this->mdl_payments->Save_Paytable($paymenttable); //$paytable=$this->mdl_payments->Save_Paytable($payt); //} // else // { // $paytable=$this->mdl_payments->Update_Paytable($paymenttable,$invoice_id); // } if(($inv_balance==1) && ($statusupdation==1) && ($paytable==1)&& ($all==$jj)) { echo "Saved Successfully"; } else if(($inv_balance!=1) && ($statusupdation!=1) && ($paytable!=1)) { echo "Something went wrong Please Try Again"; } //$email=$this->mdl_payments->GetEmailID($paymenttable); // $email_from = 'sriramv63@gmail.com'; // $this->load->helper('template'); // $this->load->model('email_templates/mdl_email_templates'); // $email_from = 'sales@resicoindustries.com'; // $email = 'nidhilaem@gmail.com'; // //$email_message = 'Invoice Payment have been done'; // // $data = $this->layout->set( // // array( // // 'invoicedetails' =>$this->mdl_payments->getinvoicedetails($receiptno), // // 'viewpayment'=>$this->mdl_payments->Get_PaymentDetails($receiptno), // // 'PaymentLineDetails'=> $this->mdl_payments->Get_InvoicelistPayment($receiptno), // // ) // // ); // $this->load->helper('mailer'); // if (mailer_configured()) // { // $this->load->helper('mailer/phpmailer'); // // print_r($data);die; // $email_message = ''; // $email_message .='
//

21

//
//
//
//
//

//
S.NoAmount
1150
'; // $email_template = $this->mdl_email_templates->get_by_id(2); // if (!phpmail_send($email_from, $email, trans('Invoice Payment'), $email_message)) // { // $email_failed = true; // } // } // else // { // $this->load->library('email'); // // Set email configuration // $config['mailtype'] = 'html'; // $this->email->initialize($config); // // Set the email params // $this->email->from($email_from); // $this->email->to($email); // $this->email->subject('test'); // $this->email->message($email_message); // // Send the reset email // if (!$this->email->send()) // { // $email_failed = true; // log_message('error', $this->email->print_debugger()); // } // } } function GetReceiptno() { $receipt=$this->mdl_payments->GetReceiptid(); if(!empty($receipt)){ $receipt = $receipt; }else{ $receipt = 1; } echo json_encode($receipt);die; } function ShowPaymentView($id) { // echo $id; $this->layout->set( array( 'viewpayment' => $this->mdl_payments->Get_PaymentDetails($id), 'PaymentLineDetails' => $this->mdl_payments->Get_InvoicelistPayment($id), 'invoicedetails' => $this->mdl_payments->getinvoicedetails($id), ) ); $this->layout->buffer('content', 'payments/paymentslip'); $this->layout->render(); } function ShowEmailView($id) { // echo $id; $this->layout->set( array( 'viewpayment' => $this->mdl_payments->Get_PaymentDetails($id), 'PaymentLineDetails' => $this->mdl_payments->Get_InvoicelistPayment($id), 'invoicedetails' => $this->mdl_payments->getinvoicedetails($id), ) ); $this->layout->buffer('content', 'payments/editform'); $this->layout->render(); } function Show_PaymentSlip() { $receiptno= $this->input->post('pid'); $invoicedetails =$this->mdl_payments->getinvoicedetails($receiptno); $viewpayment=$this->mdl_payments->Get_PaymentDetails($receiptno); $PaymentLineDetails=$this->mdl_payments->Get_InvoicelistPayment($receiptno); $userdetails=$this->mdl_payments->GetuserDetails(1); if(!empty($userdetails)) { foreach ($userdetails as $user) { $user_company=$user->user_company; $user_address_1=$user->user_address_1; $user_address_2=$user->user_address_2; $user_city=$user->user_city; $user_state=$user->user_state; $user_zip=$user->user_zip; } } if(!empty($invoicedetails)) { foreach($invoicedetails as $inv) { $inv_id= $inv->invoice_id; $receiptno=$inv->receipt_no; $clientsname=$inv->client_name; $clientphone= $inv->client_phone; $clientemail= $inv->client_email; $client_address_1=$inv->client_address_1; $client_address_2=$inv->client_address_2; $client_city=$inv->client_city; $client_state= $inv->client_state; $client_zip= $inv->client_zip; $pdt=new DateTime($inv->payment_date,new DateTimeZone('Asia/Kolkata')); $paydt=$pdt->format('d-m-Y'); $Paymethod=$inv->payment_method_name; $totalamt=$inv->total_payment; $client_id=$inv->client_id; } } $Emailid=$this->mdl_payments->Get_mailid($client_id); if(!empty($Emailid)) { foreach($Emailid as $eid) { $clientid=$eid->client_email; } } //echo $clientid; //echo "foreach out".$invoice_number;die; $data = $this->layout->set( array( 'invoicedetails' =>$this->mdl_payments->getinvoicedetails($receiptno), 'viewpayment'=>$this->mdl_payments->Get_PaymentDetails($receiptno), 'PaymentLineDetails'=> $this->mdl_payments->Get_InvoicelistPayment($receiptno), ) ); $this->load->helper('template'); $this->load->model('email_templates/mdl_email_templates'); $email_from = 'sales@resicoindustries.com'; //$email = 'nidhilaem@gmail.com'; $email = $clientid; $this->load->helper('mailer'); if (mailer_configured()) { $this->load->helper('mailer/phpmailer'); // print_r($data);die; $email_message ='Dear customer, payment for the following invoices have been done

'; $email_message .='
'.'

'.$user_company.'


'.$user_address_1.'
'.$user_address_2.'
'.$user_city.'
'.$user_state .'
'.$user_zip.'
'; $email_message .= '

PAYMENT RECEIPT

'; // $email_message .= '
//
//
// // // // // // // // // //
Payment Date:'.$paydt.'
Receipt Method:'.$Paymethod.'
//
//
//

'; $email_message .= '
Payment Date : '.$paydt.' Total Receipt
Receipt Method: '.$Paymethod.' RS : '.$totalamt.'
'; $email_message .='

Received From:
'.$clientsname.'
'.$client_address_1.'
'.$client_address_2.'
'.$client_city.'
'.$client_state ." - " .$client_zip.'

'; $email_message .='
Towards Payment For

'; $email_message .= "
"; foreach($PaymentLineDetails as $pay) { $amount_paid = ($pay->invoice_total-$pay->invoice_balance); $email_message .=" "; } $email_message .= "
Invoice No Item Description Quantity Sales With Tax Amount Paid
".$pay->invoice_number." ".$pay->item_description." ".$pay->item_quantity." ".$pay->invoice_total." ".$pay->payment_amount."

Total".'-'.$totalamt.'

' ; if (!phpmail_send($email_from, $email, trans('Invoice Payment'), $email_message)) { $email_failed = true; } } else { $this->load->library('email'); // Set email configuration $config['mailtype'] = 'html'; $this->email->initialize($config); // Set the email params $this->email->from($email_from); $this->email->to($email); $this->email->subject('test'); $this->email->message($email_message); // Send the reset email if (!$this->email->send()) { $email_failed = true; log_message('error', $this->email->print_debugger()); } } } }