|
1
|
|
|
<?php |
|
2
|
|
|
############################################################################### |
|
3
|
|
|
# ASTPP - Open Source VoIP Billing Solution |
|
4
|
|
|
# |
|
5
|
|
|
# Copyright (C) 2016 iNextrix Technologies Pvt. Ltd. |
|
6
|
|
|
# Samir Doshi <[email protected]> |
|
7
|
|
|
# ASTPP Version 3.0 and above |
|
8
|
|
|
# License https://www.gnu.org/licenses/agpl-3.0.html |
|
9
|
|
|
# |
|
10
|
|
|
# This program is free software: you can redistribute it and/or modify |
|
11
|
|
|
# it under the terms of the GNU Affero General Public License as |
|
12
|
|
|
# published by the Free Software Foundation, either version 3 of the |
|
13
|
|
|
# License, or (at your option) any later version. |
|
14
|
|
|
# |
|
15
|
|
|
# This program is distributed in the hope that it will be useful, |
|
16
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
17
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
18
|
|
|
# GNU Affero General Public License for more details. |
|
19
|
|
|
# |
|
20
|
|
|
# You should have received a copy of the GNU Affero General Public License |
|
21
|
|
|
# along with this program. If not, see <http://www.gnu.org/licenses/>. |
|
22
|
|
|
############################################################################### |
|
23
|
|
|
class Invoices extends MX_Controller { |
|
24
|
|
|
|
|
25
|
|
|
function Invoices() { |
|
26
|
|
|
parent::__construct(); |
|
|
|
|
|
|
27
|
|
|
|
|
28
|
|
|
$this->load->helper('template_inheritance'); |
|
29
|
|
|
|
|
30
|
|
|
$this->load->library('session'); |
|
31
|
|
|
$this->load->library('invoices_form'); |
|
32
|
|
|
$this->load->library('astpp/form'); |
|
33
|
|
|
$this->load->model('invoices_model'); |
|
34
|
|
|
$this->load->model('Astpp_common'); |
|
35
|
|
|
$this->load->model('common_model'); |
|
36
|
|
|
$this->load->library("astpp/email_lib"); |
|
37
|
|
|
$this->load->library('fpdf'); |
|
38
|
|
|
$this->load->library('pdf'); |
|
39
|
|
|
|
|
40
|
|
|
if ($this->session->userdata('user_login') == FALSE) |
|
41
|
|
|
redirect(base_url() . '/astpp/login'); |
|
42
|
|
|
} |
|
43
|
|
|
|
|
44
|
|
|
|
|
45
|
|
|
function invoice_list() { |
|
46
|
|
|
|
|
47
|
|
|
$data['username'] = $this->session->userdata('user_name'); |
|
|
|
|
|
|
48
|
|
|
$data['page_title'] = 'Invoices'; |
|
49
|
|
|
$data['login_type'] = $this->session->userdata['userlevel_logintype']; |
|
50
|
|
|
$data['search_flag'] = true; |
|
51
|
|
|
$this->session->set_userdata('advance_search',0); |
|
52
|
|
|
$data['grid_fields']= $this->invoices_form->build_invoices_list_for_admin(); |
|
53
|
|
|
$data["grid_buttons"] = $this->invoices_form->build_grid_buttons(); |
|
54
|
|
|
$data['form_search']=$this->form->build_serach_form($this->invoices_form->get_invoice_search_form()); |
|
55
|
|
|
$account=$this->db_model->getSelect('id,first_name,last_name,number', 'accounts', array('status'=>0,'type'=>'0,3','deleted'=>0)) ; |
|
56
|
|
|
$data['account_value']=$account->result_array(); |
|
57
|
|
|
$this->load->view('view_invoices_list',$data); |
|
58
|
|
|
} |
|
59
|
|
|
function invoice_list_json() { |
|
60
|
|
|
$login_info = $this->session->userdata('accountinfo'); |
|
61
|
|
|
$logintype = $this->session->userdata('logintype'); |
|
62
|
|
|
$json_data = array(); |
|
63
|
|
|
$count_all = $this->invoices_model->get_invoice_list(false); |
|
64
|
|
|
$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
|
65
|
|
|
$json_data = $paging_data["json_paging"]; |
|
66
|
|
|
$result_query = $this->invoices_model->get_invoice_list(true,$paging_data["paging"]["start"], $paging_data["paging"]["page_no"]); |
|
67
|
|
|
if($logintype == -1){ |
|
68
|
|
|
$currency_id = Common_model::$global_config['system_config']['base_currency']; |
|
69
|
|
|
}else{ |
|
70
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $login_info["currency_id"]); |
|
|
|
|
|
|
71
|
|
|
$currency_id = $accountdata["currency_id"]; |
|
72
|
|
|
} |
|
73
|
|
|
$grid_fields= json_decode($this->invoices_form->build_invoices_list_for_admin()); |
|
74
|
|
|
$url= ($logintype==0 ||$logintype==3 ) ? "/user/user_invoice_download/":'/invoices/invoice_download/'; |
|
75
|
|
|
if($result_query->num_rows > 0 ){ |
|
76
|
|
|
$query=$result_query->result_array(); |
|
77
|
|
|
$total_value = 0; |
|
78
|
|
|
$ountstanding_value = 0; |
|
79
|
|
|
foreach ($query as $key => $value) { |
|
80
|
|
|
$delete_button=''; |
|
81
|
|
|
$date = strtotime($value['invoice_date']); |
|
82
|
|
|
$invoice_date =date("Y-m-d",$date); |
|
83
|
|
|
$fromdate = strtotime($value['from_date']); |
|
84
|
|
|
$from_date =date("Y-m-d",$fromdate); |
|
85
|
|
|
$duedate = strtotime($value['due_date']); |
|
86
|
|
|
if($value['type'] == 'I'){ |
|
87
|
|
|
$due_date =date("Y-m-d",$duedate); |
|
88
|
|
|
}else{ |
|
89
|
|
|
$due_date=''; |
|
90
|
|
|
} |
|
91
|
|
|
$outstanding = $value['amount']; |
|
92
|
|
|
$last_payment_date = ''; |
|
93
|
|
|
$invoice_total_query = $this->db_model->select("sum(debit) as debit,sum(credit) as credit,created_date", "invoice_details", array("invoiceid"=> $value['id'],"item_type"=>"INVPAY"),"created_date","DESC","1","0"); |
|
94
|
|
|
// echo $this->db->last_query(); exit; |
|
|
|
|
|
|
95
|
|
|
if ($invoice_total_query ->num_rows() > 0){ |
|
96
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
97
|
|
|
//echo '<pre>'; print_r($invoice_total_query); |
|
|
|
|
|
|
98
|
|
|
if($value['type'] == 'I'){ |
|
99
|
|
|
$outstanding -= $this->common->currency_decimal($invoice_total_query[0]['credit']); |
|
100
|
|
|
}else{ |
|
101
|
|
|
$outstanding=''; |
|
102
|
|
|
} |
|
103
|
|
|
$last_payment_date = $invoice_total_query[0]['created_date']; |
|
104
|
|
|
if($value['type'] == 'I'){ |
|
105
|
|
|
if($last_payment_date ){ |
|
106
|
|
|
$payment_date=strtotime( $last_payment_date); |
|
107
|
|
|
$payment_last=date("Y-m-d",$payment_date); |
|
108
|
|
|
}else{ |
|
109
|
|
|
$payment_last=''; |
|
110
|
|
|
} |
|
111
|
|
|
}else{ |
|
112
|
|
|
$payment_last=''; |
|
113
|
|
|
} |
|
114
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
$invoice_total=''; |
|
118
|
|
|
$accountinfo=$this->session->userdata('accountinfo'); |
|
119
|
|
|
$id=$accountinfo['id']; |
|
120
|
|
|
if($accountinfo['type'] == 1){ |
|
121
|
|
|
$query ="select sum(amount) as grand_total from invoices where reseller_id='$id'"; |
|
122
|
|
|
}else{ |
|
123
|
|
|
$query ="select sum(amount) as grand_total from invoices where reseller_id='0'"; |
|
124
|
|
|
} |
|
125
|
|
|
$ext_query=$this->db->query($query); |
|
126
|
|
View Code Duplication |
if($ext_query->num_rows() > 0){ |
|
127
|
|
|
$result_total=$ext_query->result_array(); |
|
128
|
|
|
$grandtotal=$result_total[0]['grand_total']; |
|
129
|
|
|
$grand_total=$this->common->currency_decimal($grandtotal).' '.$currency_id; |
|
130
|
|
|
} |
|
131
|
|
|
|
|
132
|
|
|
|
|
133
|
|
|
if($accountinfo['type'] == 1){ |
|
134
|
|
|
$invoice_query ="select sum(credit) as grand_credit from invoice_details where reseller_id='$id'"; |
|
135
|
|
|
}else{ |
|
136
|
|
|
$invoice_query ="select sum(credit) as grand_credit from invoice_details where reseller_id='0'"; |
|
137
|
|
|
} |
|
138
|
|
|
$credit_query=$this->db->query($invoice_query); |
|
139
|
|
View Code Duplication |
if($credit_query->num_rows() > 0){ |
|
140
|
|
|
$credit_total=$credit_query->result_array(); |
|
141
|
|
|
$grand_credit_total=$credit_total[0]['grand_credit']; |
|
142
|
|
|
$grandcredit=$grand_total-$grand_credit_total; |
|
|
|
|
|
|
143
|
|
|
$grand_credit=$this->common->currency_decimal($grandcredit).' '.$currency_id; |
|
144
|
|
|
} |
|
145
|
|
|
$download="<a href=" . $url .$value['id'].'/00_'.$value['invoice_prefix'].$value['invoiceid']. " class='btn btn-royelblue btn-sm' title='Download Invoice' ><i class='fa fa-cloud-download fa-fw'></i></a> "; |
|
146
|
|
|
if($value['type'] == 'I'){ |
|
147
|
|
|
if($value['confirm'] ==0){ |
|
148
|
|
|
if($value['generate_type'] ==1){ |
|
149
|
|
|
$payment = '<a href="'. base_url() .'invoices/invoice_manually_edit/' . $value['id'] . '" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>'; |
|
150
|
|
|
}else{ |
|
151
|
|
|
$payment = '<a href="'. base_url() .'invoices/invoice_automatically_edit/' . $value['id'] . '" class="btn btn-royelblue btn-sm" title="Edit"><i class="fa fa-pencil-square-o fa-fw"></i></a>'; |
|
152
|
|
|
} |
|
153
|
|
|
$id=$value['id']; |
|
154
|
|
|
$delete_button="<a onclick='invoice_delete($id)' class='btn btn-royelblue btn-sm' title='Delete' ><i class='fa fa-trash fa-fw'></i></a> "; |
|
155
|
|
|
|
|
156
|
|
|
}else{ |
|
157
|
|
|
if($outstanding > 0){ |
|
158
|
|
|
$payment = '<a style="padding: 0 8px;" href="'. base_url() .'invoices/invoice_summary/' . $value['id'] . '" class="btn btn-warning" title="Payment">Unpaid</i></a>'; |
|
159
|
|
|
}else{ |
|
160
|
|
|
$payment = '<button style="padding: 0 17px;" type="button" class="btn btn-success">Paid</button>'; |
|
161
|
|
|
} |
|
162
|
|
|
$delete_button=" "; |
|
163
|
|
|
} |
|
164
|
|
|
}else{ |
|
165
|
|
|
$payment = ''; |
|
166
|
|
|
} |
|
167
|
|
|
$account_arr = $this->db_model->getSelect('first_name,number,last_name','accounts', array('id'=>$value['accountid'])); |
|
168
|
|
|
$account_array = $account_arr->result_array(); |
|
169
|
|
|
if($value['generate_type'] == 1){ |
|
170
|
|
|
$invoice_type='Manually'; |
|
171
|
|
|
}else{ |
|
172
|
|
|
$invoice_type='Automatically'; |
|
173
|
|
|
} |
|
174
|
|
|
if($value['deleted'] == 1){ |
|
175
|
|
|
$download=''; |
|
176
|
|
|
$payment='<button style="padding: 0 17px;" type="button" class="btn btn-line-sky">Deleted</button>'; |
|
177
|
|
|
$delete_button=''; |
|
178
|
|
|
} |
|
179
|
|
|
|
|
180
|
|
|
if($value['deleted'] == 1){ |
|
181
|
|
|
$download=''; |
|
182
|
|
|
$payment='<button style="padding: 0 17px;" type="button" class="btn btn-line-sky">Deleted</button>'; |
|
183
|
|
|
$delete_button=''; |
|
184
|
|
|
} |
|
185
|
|
|
if($value['type'] == 'R'){ |
|
186
|
|
|
$icon = '<div class="flx_font flx_magenta">R</div>'; |
|
187
|
|
|
} else |
|
188
|
|
|
{ |
|
189
|
|
|
$icon = '<div class="flx_font flx_drk_pink">I</div>'; |
|
190
|
|
|
|
|
191
|
|
|
} |
|
192
|
|
|
|
|
193
|
|
|
$json_data['rows'][] = array('cell' => array( |
|
194
|
|
|
|
|
195
|
|
|
$value['invoice_prefix'].$value['invoiceid'].$icon, |
|
196
|
|
|
//$value['invoice_prefix'].$value['invoiceid'].'('.$value['type'].')', |
|
|
|
|
|
|
197
|
|
|
$invoice_type, |
|
198
|
|
|
$account_array[0]['first_name'].' '.$account_array[0]['last_name'].'</br>'.$account_array[0]['number'], |
|
199
|
|
|
$invoice_date, |
|
200
|
|
|
$from_date, |
|
201
|
|
|
$due_date, |
|
202
|
|
|
$payment_last, |
|
|
|
|
|
|
203
|
|
|
$this->common->currency_decimal($this->common_model->calculate_currency($value['amount'])), |
|
204
|
|
|
$this->common->currency_decimal($this->common_model->calculate_currency($outstanding)), |
|
205
|
|
|
$download.''.$payment.' '.$delete_button, |
|
206
|
|
|
|
|
207
|
|
|
)); |
|
208
|
|
|
$total_value=$total_value + $value['amount']; |
|
209
|
|
|
$ountstanding_value=$ountstanding_value + $outstanding; |
|
210
|
|
|
} |
|
211
|
|
|
} |
|
212
|
|
|
echo json_encode($json_data); |
|
213
|
|
|
|
|
214
|
|
|
} |
|
215
|
|
|
function invoice_manually_edit($id){ |
|
216
|
|
|
$confirm = $this->common->get_field_name('confirm', 'invoices', $id); |
|
217
|
|
|
$deleted = $this->common->get_field_name('deleted', 'invoices', $id); |
|
218
|
|
|
if($confirm == 1 || $deleted == 1){ |
|
219
|
|
|
redirect(base_url() . 'invoices/invoice_list/'); |
|
220
|
|
|
} |
|
221
|
|
|
$data['total_tax_dis']=0; |
|
|
|
|
|
|
222
|
|
|
$data['total_credit_dis']=0; |
|
223
|
|
|
$query="SELECT * from invoice_details where generate_type=1 AND invoiceid='$id' "; |
|
224
|
|
|
$invoice_total_query=$this->db->query($query); |
|
225
|
|
|
$data['count']=0; |
|
226
|
|
|
$data['row_count']=5; |
|
227
|
|
|
if ($invoice_total_query->num_rows() > 0) { |
|
228
|
|
|
$count=$invoice_total_query ->num_rows(); |
|
229
|
|
|
$data['count']=$count; |
|
230
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
231
|
|
|
$i=1; |
|
232
|
|
|
$taxi=0; |
|
233
|
|
|
$get_data=array(); |
|
234
|
|
|
$data['total_tax_dis']=array(); |
|
235
|
|
|
foreach($invoice_total_query as $value){ |
|
236
|
|
View Code Duplication |
if($value['item_type'] == 'TAX'){ |
|
237
|
|
|
$data['total_tax_dis'][$taxi]=$value['debit']; |
|
238
|
|
|
$taxi++; |
|
239
|
|
|
}else{ |
|
240
|
|
|
if($i >= 5){ |
|
241
|
|
|
$data['row_count']=$i+1; |
|
242
|
|
|
} |
|
243
|
|
|
$get_data['invoice_from_date_'.$i]=$value['created_date']; |
|
244
|
|
|
$get_data['invoice_description_'.$i]=$value['description']; |
|
245
|
|
|
$get_data['invoice_amount_'.$i]=$value['debit']; |
|
246
|
|
|
$i++; |
|
247
|
|
|
$data['total_credit_dis'] += $value['debit']; |
|
248
|
|
|
} |
|
249
|
|
|
} |
|
250
|
|
|
$data['get_data']=$get_data; |
|
251
|
|
|
} |
|
252
|
|
|
$account_data = $this->session->userdata("accountinfo"); |
|
253
|
|
|
$logintype = $this->session->userdata('logintype'); |
|
254
|
|
|
$invoice_total=''; |
|
255
|
|
|
$query="SELECT * from invoice_details where item_type='INVPAY' AND invoiceid='$id' ORDER BY created_date ASC"; |
|
256
|
|
|
$invoice = $this->db_model->getSelect("*", "invoices", array("id"=> $id)); |
|
257
|
|
View Code Duplication |
if ($invoice ->num_rows() > 0) { |
|
258
|
|
|
$invoice= $invoice->result_array(); |
|
259
|
|
|
$result=$invoice[0]; |
|
260
|
|
|
$data['payment_due_date']=$result['due_date']; |
|
261
|
|
|
} |
|
262
|
|
|
|
|
263
|
|
|
$accountdata = $this->db_model->getSelect("*","accounts",array("id"=> $result['accountid'])); |
|
|
|
|
|
|
264
|
|
|
if ($accountdata ->num_rows() > 0) { |
|
265
|
|
|
$accountdata = $accountdata->result_array(); |
|
266
|
|
|
$accountdata = $accountdata[0]; |
|
267
|
|
|
} |
|
268
|
|
|
$data['taxes_count']= 0; |
|
269
|
|
|
$taxes = $this->db_model->getSelect("*","taxes_to_accounts",array("accountid"=> $result['accountid'])); |
|
270
|
|
|
$total_tax=0; |
|
271
|
|
|
$data['taxes_count']= $taxes->num_rows(); |
|
272
|
|
View Code Duplication |
if ($taxes ->num_rows() > 0) { |
|
273
|
|
|
$taxes = $taxes->result_array(); |
|
274
|
|
|
foreach($taxes as $tax_value){ |
|
275
|
|
|
$taxe_res = $this->db_model->getSelect("*","taxes",array("id"=> $tax_value['taxes_id'])); |
|
276
|
|
|
$taxe_res = $taxe_res->result_array(); |
|
277
|
|
|
foreach($taxe_res as $taxe_res_val){ |
|
278
|
|
|
$data['taxes_to_accounts'][]= $taxe_res_val; |
|
279
|
|
|
$total_tax +=$taxe_res_val['taxes_rate']; |
|
280
|
|
|
} |
|
281
|
|
|
} |
|
282
|
|
|
} |
|
283
|
|
|
|
|
284
|
|
|
$system_config = common_model::$global_config['system_config']; |
|
285
|
|
View Code Duplication |
if($system_config["paypal_mode"]==0){ |
|
286
|
|
|
$data["paypal_url"] = $system_config["paypal_url"]; |
|
287
|
|
|
$data["paypal_email_id"] = $system_config["paypal_id"]; |
|
288
|
|
|
}else{ |
|
289
|
|
|
$data["paypal_url"] = $system_config["paypal_sandbox_url"]; |
|
290
|
|
|
$data["paypal_email_id"] = $system_config["paypal_sandbox_id"]; |
|
291
|
|
|
} |
|
292
|
|
|
$date = strtotime($result['invoice_date']); |
|
293
|
|
|
$data['time'] = date("Y-m-d h:i:s ",$date); |
|
294
|
|
|
$data["paypal_tax"] = $system_config["paypal_tax"]; |
|
295
|
|
|
$data["from_currency"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
296
|
|
|
$data["to_currency"] = Common_model::$global_config['system_config']['base_currency']; |
|
297
|
|
View Code Duplication |
if($account_data['type'] == -1){ |
|
298
|
|
|
$data["to_currency"] = $data["to_currency"]; |
|
299
|
|
|
} elseif($account_data['type'] == 1){ |
|
300
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
301
|
|
|
$data["to_currency"] = $accountdata["currency_id"]; |
|
302
|
|
|
} else{ |
|
303
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
304
|
|
|
$data["to_currency"] = $accountdata["currency_id"]; |
|
305
|
|
|
} |
|
306
|
|
|
$data['total_tax']=$total_tax; |
|
307
|
|
|
$data['invoice_notes']=$result['notes']; |
|
308
|
|
|
$data['from_date']=$result['from_date']; |
|
309
|
|
|
$data['to_date']=$result['to_date']; |
|
310
|
|
|
$data['invoice_date']=$result['invoice_date']; |
|
311
|
|
|
$data['amount'] = $this->common_model->calculate_currency($result['amount'],'','','',''); |
|
312
|
|
|
$data['invoice_prefix'] = $result['invoice_prefix']; |
|
313
|
|
|
$data['page_title'] = 'Invoice Summary'; |
|
314
|
|
|
$data['invoice_date']=$result['invoice_date']; |
|
315
|
|
|
$data['return'] =base_url() . "invoices/invoice_list_modified"; |
|
316
|
|
|
$data['cancel_return'] =base_url()."invoice/invoice_list_cancel"; |
|
317
|
|
|
$data['paypal_mode'] = 1; |
|
318
|
|
|
$data['prefix_id']=$result['invoiceid']; |
|
319
|
|
|
$data['logintype']=$logintype; |
|
320
|
|
|
$data['accountdata'] = $accountdata; |
|
321
|
|
|
$data['id']=$id; |
|
322
|
|
|
$data['notify_url'] = base_url() . "invoices/invoice_list_get_data"; |
|
323
|
|
View Code Duplication |
if($account_data['type'] =='1'){ |
|
324
|
|
|
$data['response_url'] = base_url() . "invoices/invoice_list_responce/"; |
|
325
|
|
|
} else{ |
|
326
|
|
|
$data['response_url'] = base_url() . "user/user_list_responce/"; |
|
327
|
|
|
} |
|
328
|
|
|
$data['sucess_url'] = base_url() . "invoices/invoice_list_sucess"; |
|
329
|
|
|
$this->load->view('view_invoice_edit_manually',$data); |
|
330
|
|
|
} |
|
331
|
|
|
function invoice_automatically_edit($id){ |
|
332
|
|
|
$confirm = $this->common->get_field_name('confirm', 'invoices', $id); |
|
333
|
|
|
$deleted = $this->common->get_field_name('deleted', 'invoices', $id); |
|
334
|
|
|
if($confirm == 1 || $deleted == 1){ |
|
335
|
|
|
redirect(base_url() . 'invoices/invoice_list/'); |
|
336
|
|
|
} |
|
337
|
|
|
$data['total_tax_dis']=0; |
|
|
|
|
|
|
338
|
|
|
$data['total_credit_dis']=0; |
|
339
|
|
|
$query="SELECT * from invoice_details where invoiceid='$id' "; |
|
340
|
|
|
$invoice_total_query=$this->db->query($query); |
|
341
|
|
|
$data['count']=0; |
|
342
|
|
|
$data['row_count']=5; |
|
343
|
|
|
if ($invoice_total_query->num_rows() > 0) { |
|
344
|
|
|
$count=$invoice_total_query ->num_rows(); |
|
345
|
|
|
$data['count']=$count; |
|
346
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
347
|
|
|
$i=1;$taxi=0; |
|
348
|
|
|
$get_data=array(); |
|
349
|
|
|
$data['total_tax_dis']=array(); |
|
350
|
|
|
$data['total_credit_sum']=0; |
|
351
|
|
|
foreach($invoice_total_query as $value){ |
|
352
|
|
|
if($value['item_type'] == 'TAX'){ |
|
353
|
|
|
$data['total_tax_dis'][$taxi]=$value['debit']; |
|
354
|
|
|
$taxi++; |
|
355
|
|
View Code Duplication |
} else{ |
|
356
|
|
|
if($value['generate_type'] == 1){ |
|
357
|
|
|
if($i >= 5){ |
|
358
|
|
|
$data['row_count']=$i+1; |
|
359
|
|
|
} |
|
360
|
|
|
$get_data['invoice_from_date_'.$i]=$value['created_date']; |
|
361
|
|
|
$get_data['invoice_description_'.$i]=$value['description']; |
|
362
|
|
|
$get_data['invoice_amount_'.$i]=$value['debit']; |
|
363
|
|
|
$i++; |
|
364
|
|
|
$data['total_credit_dis'] += $value['debit']; |
|
365
|
|
|
} |
|
366
|
|
|
$data['total_credit_sum'] += $value['debit']; |
|
367
|
|
|
} |
|
368
|
|
|
} |
|
369
|
|
|
$data['get_data']=$get_data; |
|
370
|
|
|
} |
|
371
|
|
|
$account_data = $this->session->userdata("accountinfo"); |
|
372
|
|
|
$logintype = $this->session->userdata('logintype'); |
|
373
|
|
|
$invoice_total=''; |
|
374
|
|
|
$query="SELECT * from invoice_details where invoiceid='$id' and generate_type=0 and item_type != 'TAX' ORDER BY id ASC"; |
|
375
|
|
|
$invoice_total_query=$this->db->query($query); |
|
376
|
|
|
$data['auto_count']=0; |
|
377
|
|
|
if ($invoice_total_query ->num_rows() > 0) { |
|
378
|
|
|
$data['auto_count']=$invoice_total_query ->num_rows(); |
|
379
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
380
|
|
|
|
|
381
|
|
|
$data['invoice_total_query']=$invoice_total_query; |
|
382
|
|
|
} |
|
383
|
|
|
$invoice = $this->db_model->getSelect("*", "invoices", array("id"=> $id)); |
|
384
|
|
View Code Duplication |
if ($invoice ->num_rows() > 0) { |
|
385
|
|
|
$invoice= $invoice->result_array(); |
|
386
|
|
|
$result=$invoice[0]; |
|
387
|
|
|
$data['payment_due_date']=$result['due_date']; |
|
388
|
|
|
} |
|
389
|
|
|
$invoice_auto_res = $this->db_model->getSelect("sum(debit) as debit", "invoice_details", array("invoiceid"=> $id,'generate_type'=>0)); |
|
390
|
|
|
$data['invoice_auto_res']=0; |
|
391
|
|
|
if ($invoice_auto_res ->num_rows() > 0) { |
|
392
|
|
|
$invoice_auto_res= $invoice_auto_res->result_array(); |
|
393
|
|
|
$result_auto_res=$invoice_auto_res[0]; |
|
394
|
|
|
$data['invoice_auto_res'] =$result_auto_res['debit']; |
|
395
|
|
|
} |
|
396
|
|
|
|
|
397
|
|
|
$accountdata = $this->db_model->getSelect("*","accounts",array("id"=> $result['accountid'])); |
|
|
|
|
|
|
398
|
|
|
if ($accountdata ->num_rows() > 0) { |
|
399
|
|
|
$accountdata = $accountdata->result_array(); |
|
400
|
|
|
$accountdata = $accountdata[0]; |
|
401
|
|
|
} |
|
402
|
|
|
$data['taxes_count']= 0; |
|
403
|
|
|
$taxes = $this->db_model->getSelect("*","taxes_to_accounts",array("accountid"=> $result['accountid'])); |
|
404
|
|
|
$data['taxes_count']= $taxes->num_rows(); |
|
405
|
|
|
$total_tax=0; |
|
406
|
|
View Code Duplication |
if ($taxes ->num_rows() > 0) { |
|
407
|
|
|
$taxes = $taxes->result_array(); |
|
408
|
|
|
foreach($taxes as $tax_value){ |
|
409
|
|
|
$taxe_res = $this->db_model->getSelect("*","taxes",array("id"=> $tax_value['taxes_id'])); |
|
410
|
|
|
$taxe_res = $taxe_res->result_array(); |
|
411
|
|
|
foreach($taxe_res as $taxe_res_val){ |
|
412
|
|
|
$data['taxes_to_accounts'][]= $taxe_res_val; |
|
413
|
|
|
$total_tax +=$taxe_res_val['taxes_rate']; |
|
414
|
|
|
} |
|
415
|
|
|
} |
|
416
|
|
|
} |
|
417
|
|
|
|
|
418
|
|
|
$system_config = common_model::$global_config['system_config']; |
|
419
|
|
View Code Duplication |
if($system_config["paypal_mode"]==0){ |
|
420
|
|
|
$data["paypal_url"] = $system_config["paypal_url"]; |
|
421
|
|
|
$data["paypal_email_id"] = $system_config["paypal_id"]; |
|
422
|
|
|
}else{ |
|
423
|
|
|
$data["paypal_url"] = $system_config["paypal_sandbox_url"]; |
|
424
|
|
|
$data["paypal_email_id"] = $system_config["paypal_sandbox_id"]; |
|
425
|
|
|
} |
|
426
|
|
|
$date = strtotime($result['invoice_date']); |
|
427
|
|
|
$data['total_tax']=$total_tax; |
|
428
|
|
|
$data['time'] = date("Y-m-d h:i:s ",$date); |
|
429
|
|
|
$data["paypal_tax"] = $system_config["paypal_tax"]; |
|
430
|
|
|
$data["from_currency"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
431
|
|
|
$data["to_currency"] = Common_model::$global_config['system_config']['base_currency']; |
|
432
|
|
View Code Duplication |
if($account_data['type'] == -1){ |
|
433
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
434
|
|
|
$data["to_currency"] = $accountdata["currency_id"]; |
|
435
|
|
|
}elseif($account_data['type'] == 1){ |
|
436
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
437
|
|
|
$data["to_currency"] = $accountdata["currency_id"]; |
|
438
|
|
|
}else{ |
|
439
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
440
|
|
|
$data["to_currency"] = $accountdata["currency_id"]; |
|
441
|
|
|
} |
|
442
|
|
|
$data['from_date']=$result['from_date']; |
|
443
|
|
|
$data['to_date']=$result['to_date']; |
|
444
|
|
|
$data['invoice_notes']=$result['notes']; |
|
445
|
|
|
$data['invoice_date']=$result['invoice_date']; |
|
446
|
|
|
$data['amount'] = $this->common_model->calculate_currency($result['amount'],'','','',''); |
|
447
|
|
|
$data['invoice_prefix'] = $result['invoice_prefix']; |
|
448
|
|
|
$data['page_title'] = 'Invoice Summary'; |
|
449
|
|
|
$data['invoice_date']=$result['invoice_date']; |
|
450
|
|
|
$data['return'] =base_url() . "invoices/invoice_list_modified"; |
|
451
|
|
|
$data['cancel_return'] =base_url()."invoice/invoice_list_cancel"; |
|
452
|
|
|
$data['paypal_mode'] = 1; |
|
453
|
|
|
$data['prefix_id']=$result['invoiceid']; |
|
454
|
|
|
$data['logintype']=$logintype; |
|
455
|
|
|
$data['accountdata'] = $accountdata; |
|
456
|
|
|
$data['id']=$id; |
|
457
|
|
|
$data['notify_url'] = base_url() . "invoices/invoice_list_get_data"; |
|
458
|
|
View Code Duplication |
if($account_data['type'] =='1'){ |
|
459
|
|
|
$data['response_url'] = base_url() . "invoices/invoice_list_responce/"; |
|
460
|
|
|
} else{ |
|
461
|
|
|
$data['response_url'] = base_url() . "user/user_list_responce/"; |
|
462
|
|
|
} |
|
463
|
|
|
$data['sucess_url'] = base_url() . "invoices/invoice_list_sucess"; |
|
464
|
|
|
|
|
465
|
|
|
$this->load->view('view_invoice_edit_automatically',$data); |
|
466
|
|
|
} |
|
467
|
|
|
function invoice_manually_payment_edit_save(){ |
|
468
|
|
|
$response_arr=$_POST; |
|
469
|
|
|
if(isset($response_arr['save'])){ |
|
470
|
|
|
$confirm=0; |
|
471
|
|
|
} else{ |
|
472
|
|
|
$confirm=1; |
|
473
|
|
|
} |
|
474
|
|
|
$where=array('invoiceid'=>$response_arr['invoiceid'],'generate_type'=>1); |
|
475
|
|
|
$this->db->where($where); |
|
476
|
|
|
$this->db->delete("invoice_details"); |
|
477
|
|
|
$final_bal=0; |
|
478
|
|
|
$final_tax_bal=0; |
|
479
|
|
|
$account_balance = $this->common->get_field_name('balance', 'accounts', $response_arr['accountid']); |
|
480
|
|
|
if($response_arr['taxes_count'] > 0){ |
|
481
|
|
|
for($a=0 ;$a < $response_arr['taxes_count'];$a++){ |
|
482
|
|
|
$add_arr=array( |
|
483
|
|
|
'accountid'=>$response_arr['accountid'], |
|
484
|
|
|
'reseller_id'=>$response_arr['reseller_id'], |
|
485
|
|
|
'invoiceid'=>$response_arr['invoiceid'], |
|
486
|
|
|
'item_id'=>0, |
|
487
|
|
|
'generate_type'=>1, |
|
488
|
|
|
'item_type'=>'TAX', |
|
489
|
|
|
'description'=>$response_arr['description_total_tax_input_'.$a], |
|
490
|
|
|
'debit'=>$this->common_model->add_calculate_currency($response_arr['abc_total_tax_input_'.$a],"","",true,false), |
|
491
|
|
|
'created_date'=>gmdate("Y-m-d H:i:s"), |
|
492
|
|
|
); |
|
493
|
|
|
$final_tax_bal +=$this->common_model->add_calculate_currency($response_arr['abc_total_tax_input_'.$a],"","",true,false); |
|
494
|
|
|
$this->db->insert("invoice_details",$add_arr); |
|
495
|
|
|
} |
|
496
|
|
|
} |
|
497
|
|
|
for ($i = 1; $i <= $response_arr['row_count']; $i++) { |
|
498
|
|
View Code Duplication |
if($response_arr['invoice_amount_'.$i] != ''){ |
|
499
|
|
|
$add_arr=array( |
|
500
|
|
|
'accountid'=>$response_arr['accountid'], |
|
501
|
|
|
'reseller_id'=>$response_arr['reseller_id'], |
|
502
|
|
|
'invoiceid'=>$response_arr['invoiceid'], |
|
503
|
|
|
'item_id'=>0, |
|
504
|
|
|
'generate_type'=>1, |
|
505
|
|
|
'item_type'=>'manual_inv', |
|
506
|
|
|
'description'=>$response_arr['invoice_description_'.$i], |
|
507
|
|
|
'debit'=>$this->common_model->add_calculate_currency($response_arr['invoice_amount_'.$i],"","",true,false), |
|
508
|
|
|
'created_date'=>$response_arr['invoice_from_date_'.$i], |
|
509
|
|
|
); |
|
510
|
|
|
$this->db->insert("invoice_details",$add_arr); |
|
511
|
|
|
} |
|
512
|
|
|
$final_bal += $this->common_model->add_calculate_currency($response_arr['invoice_amount_'.$i],"","",true,false); |
|
513
|
|
|
} |
|
514
|
|
|
$query="select sum(debit) as credit from invoice_details where invoiceid = ".$response_arr['invoiceid']; |
|
515
|
|
|
$invoice_total_query=$this->db->query($query); |
|
516
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
517
|
|
|
$data = array('amount' =>$this->common_model->add_calculate_currency($response_arr['total_val_final'],"","",true,false),'confirm'=>$confirm,'notes'=>$response_arr['invoice_notes']); |
|
518
|
|
|
$this->db->where("id", $response_arr['invoiceid']); |
|
519
|
|
|
$this->db->update("invoices", $data); |
|
520
|
|
|
if($confirm == 1){ |
|
521
|
|
|
$invoice_details = $this->db_model->getSelect("*", "invoice_details", array("invoiceid" => $response_arr["invoiceid"])); |
|
522
|
|
View Code Duplication |
if($invoice_details->num_rows >0){ |
|
523
|
|
|
$invoice_details_res = $invoice_details->result_array(); |
|
524
|
|
|
$after_bal=0; |
|
525
|
|
|
foreach($invoice_details_res as $details_key=>$details_value){ |
|
526
|
|
|
$before_balance_add=$account_balance-$after_bal; |
|
527
|
|
|
$after_balance_add=$before_balance_add-$details_value['debit']; |
|
528
|
|
|
$balnace_update=array('before_balance'=>$before_balance_add,'after_balance'=>$after_balance_add); |
|
529
|
|
|
$after_bal +=$details_value['debit']; |
|
530
|
|
|
$this->db->where("id", $details_value['id']); |
|
531
|
|
|
$this->db->update("invoice_details", $balnace_update); |
|
532
|
|
|
} |
|
533
|
|
|
} |
|
534
|
|
|
|
|
535
|
|
|
$account_data = $this->db_model->getSelect("*", "accounts", array("id" => $response_arr["accountid"])); |
|
536
|
|
|
$account_data = $account_data->result_array(); |
|
537
|
|
|
if($account_data[0]['posttoexternal'] == 1){ |
|
538
|
|
|
$bal_data=$account_data[0]['balance']-$this->common_model->add_calculate_currency($response_arr['total_val_final'],"","",true,false); |
|
539
|
|
|
} else{ |
|
540
|
|
|
$bal_data=$account_data[0]['balance']-$this->common_model->add_calculate_currency($response_arr['total_val_final'],"","",true,false); |
|
541
|
|
|
if($response_arr['reseller_id'] == 0){ |
|
542
|
|
|
$payment=1; |
|
543
|
|
|
} else{ |
|
544
|
|
|
$payment=$response_arr['reseller_id']; |
|
545
|
|
|
} |
|
546
|
|
|
$invoice_prefix = $this->common->get_field_name('invoice_prefix', 'invoices', $response_arr['invoiceid']); |
|
547
|
|
|
$invoice_prefix_id = $this->common->get_field_name('invoiceid', 'invoices', $response_arr['invoiceid']); |
|
548
|
|
|
$payment_arr = array("accountid"=> $response_arr["accountid"],"payment_mode"=>"1","credit"=>$this->common_model->add_calculate_currency($response_arr['total_val_final'],"","",true,false),"type"=>"invoice","payment_by"=>$payment,"notes"=>"Payment made by ".$account_data[0]['first_name']." ".$account_data[0]['last_name'].", invoices No: ".$invoice_prefix ."_".$invoice_prefix_id." ","paypalid"=>'',"txn_id"=>'','payment_date'=>gmdate('Y-m-d H:i:s')); |
|
549
|
|
|
$this->db->insert('payments', $payment_arr); |
|
550
|
|
|
$account_balance = $this->common->get_field_name('balance', 'accounts', $response_arr['accountid']); |
|
551
|
|
|
$add_arr=array( |
|
552
|
|
|
'accountid'=>$response_arr['accountid'], |
|
553
|
|
|
'reseller_id'=>$response_arr['reseller_id'], |
|
554
|
|
|
'invoiceid'=>$response_arr['invoiceid'], |
|
555
|
|
|
'item_id'=>0, |
|
556
|
|
|
'generate_type'=>1, |
|
557
|
|
|
'item_type'=>'INVPAY', |
|
558
|
|
|
'description'=>'Prepaid invoice generate', |
|
559
|
|
|
'credit'=>$this->common_model->add_calculate_currency($response_arr['total_val_final'],"","",true,false), |
|
560
|
|
|
'created_date'=>gmdate("Y-m-d H:i:s"), |
|
561
|
|
|
'before_balance'=>$account_balance, |
|
562
|
|
|
'after_balance'=>$account_balance-$this->common_model->add_calculate_currency($response_arr['total_val_final'],"","",true,false), |
|
563
|
|
|
); |
|
564
|
|
|
$this->db->insert("invoice_details",$add_arr); |
|
565
|
|
|
} |
|
566
|
|
|
$this->db->where("id", $response_arr['accountid']); |
|
567
|
|
|
$act_status=0; |
|
568
|
|
|
if($bal_data < 0 && $account_data[0]['posttoexternal'] == 0){ |
|
569
|
|
|
$act_status=1; |
|
570
|
|
|
} |
|
571
|
|
|
$balance_data = array('balance' => $bal_data,'status'=>$act_status); |
|
572
|
|
|
$this->db->update("accounts", $balance_data); |
|
573
|
|
|
/*** invoice mail ***/ |
|
574
|
|
|
$this->invoice_send_notification($response_arr['invoiceid'],$account_data[0],'manually'); |
|
575
|
|
|
/***** ***/ |
|
576
|
|
|
} |
|
577
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Invoice updated successfully!'); |
|
578
|
|
|
redirect(base_url() . 'invoices/invoice_list/'); |
|
579
|
|
|
} |
|
580
|
|
|
function invoice_automatically_payment_edit_save(){ |
|
581
|
|
|
$response_arr=$_POST; |
|
582
|
|
|
if(isset($response_arr['save'])){ |
|
583
|
|
|
$confirm=0; |
|
584
|
|
|
} else{ |
|
585
|
|
|
$confirm=1; |
|
586
|
|
|
} |
|
587
|
|
|
foreach($response_arr['auto_invoice_date'] as $key=>$val){ |
|
588
|
|
|
$data = array('debit' => $this->common_model->add_calculate_currency($response_arr['auto_invoice_amount'][$key],"","",true,false),'created_date'=>$response_arr['auto_invoice_date'][$key],'description'=>$response_arr['auto_invoice_description'][$key],'generate_type'=>0); |
|
589
|
|
|
$this->db->where("id", $key); |
|
590
|
|
|
$this->db->update("invoice_details", $data); |
|
591
|
|
|
|
|
592
|
|
|
} |
|
593
|
|
|
$where=array('invoiceid'=>$response_arr['invoiceid'],'generate_type'=>1); |
|
594
|
|
|
$this->db->where($where); |
|
595
|
|
|
$this->db->delete("invoice_details"); |
|
596
|
|
|
$final_bal=0; |
|
597
|
|
|
$final_tax_bal=0; |
|
598
|
|
|
$account_balance = $this->common->get_field_name('balance', 'accounts', $response_arr['accountid']); |
|
599
|
|
|
if($response_arr['taxes_count'] > 0){ |
|
600
|
|
|
for($a=0 ;$a < $response_arr['row_count'];$a++){ |
|
601
|
|
|
$arr_update=array('item_type'=>'TAX','id'=>$response_arr['description_total_tax_id_'.$a]); |
|
602
|
|
|
$this->db->where($arr_update); |
|
603
|
|
|
$update_arr=array( |
|
604
|
|
|
'debit'=>$this->common_model->add_calculate_currency($response_arr['abc_total_tax_input_'.$a],"","",true,false), |
|
605
|
|
|
); |
|
606
|
|
|
$final_tax_bal +=$this->common_model->add_calculate_currency($response_arr['abc_total_tax_input_'.$a],"","",true,false); |
|
607
|
|
|
$this->db->update("invoice_details",$update_arr); |
|
608
|
|
|
} |
|
609
|
|
|
} |
|
610
|
|
|
for ($i = 1; $i <=$response_arr['row_count']; $i++) { |
|
611
|
|
View Code Duplication |
if($response_arr['invoice_amount_'.$i] != ''){ |
|
612
|
|
|
$add_arr=array( |
|
613
|
|
|
'accountid'=>$response_arr['accountid'], |
|
614
|
|
|
'reseller_id'=>$response_arr['reseller_id'], |
|
615
|
|
|
'invoiceid'=>$response_arr['invoiceid'], |
|
616
|
|
|
'item_id'=>0, |
|
617
|
|
|
'generate_type'=>1, |
|
618
|
|
|
'item_type'=>'manual_inv', |
|
619
|
|
|
'description'=>$response_arr['invoice_description_'.$i], |
|
620
|
|
|
'debit'=>$this->common_model->add_calculate_currency($response_arr['invoice_amount_'.$i],"","",true,false), |
|
621
|
|
|
'created_date'=>$response_arr['invoice_from_date_'.$i], |
|
622
|
|
|
); |
|
623
|
|
|
$this->db->insert("invoice_details",$add_arr); |
|
624
|
|
|
} |
|
625
|
|
|
} |
|
626
|
|
|
$query="select sum(debit) as credit from invoice_details where invoiceid = ".$response_arr['invoiceid']; |
|
627
|
|
|
$invoice_total_query=$this->db->query($query); |
|
628
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
629
|
|
|
$data = array('amount' => $this->common_model->add_calculate_currency($response_arr['total_val_final'],"","",true,false),'confirm'=>$confirm,'notes'=>$response_arr['invoice_notes']); |
|
630
|
|
|
$this->db->where("id", $response_arr['invoiceid']); |
|
631
|
|
|
$this->db->update("invoices", $data); |
|
632
|
|
|
if($confirm == 1){ |
|
633
|
|
|
$invoice_details = $this->db_model->getSelect("*", "invoice_details", array("invoiceid" => $response_arr["invoiceid"])); |
|
634
|
|
View Code Duplication |
if($invoice_details->num_rows >0){ |
|
635
|
|
|
$invoice_details_res = $invoice_details->result_array(); |
|
636
|
|
|
$after_bal=0; |
|
637
|
|
|
foreach($invoice_details_res as $details_key=>$details_value){ |
|
638
|
|
|
if($details_value['item_type'] != 'STANDARD'){ |
|
639
|
|
|
$before_balance_add=$account_balance-$after_bal; |
|
640
|
|
|
$after_balance_add=$before_balance_add-$details_value['debit']; |
|
641
|
|
|
$balnace_update=array('before_balance'=>$before_balance_add,'after_balance'=>$after_balance_add); |
|
642
|
|
|
$after_bal +=$details_value['debit']; |
|
643
|
|
|
$this->db->where("id", $details_value['id']); |
|
644
|
|
|
$this->db->update("invoice_details", $balnace_update); |
|
645
|
|
|
} |
|
646
|
|
|
} |
|
647
|
|
|
} |
|
648
|
|
|
$account_data = $this->db_model->getSelect("*", "accounts", array("id" => $response_arr["accountid"])); |
|
649
|
|
|
$account_data = $account_data->result_array(); |
|
650
|
|
|
$invoice_not_deduct= $this->db_model->getSelect("*", "invoice_details", array("invoiceid" =>$response_arr['invoiceid'])); |
|
651
|
|
|
$standard_call_balance=0; |
|
652
|
|
|
$invoice_not_deduct = $invoice_not_deduct->result_array(); |
|
653
|
|
|
foreach($invoice_not_deduct as $key=>$invoice_nodeduct_val){ |
|
654
|
|
|
if($invoice_nodeduct_val['item_type'] == 'STANDARD'){ |
|
655
|
|
|
$standard_call_balance=$invoice_nodeduct_val['debit']; |
|
656
|
|
|
} |
|
657
|
|
|
} |
|
658
|
|
|
if($account_data[0]['posttoexternal'] == 1){ |
|
659
|
|
|
$finaldeduct_bal=$response_arr['total_val_final']-$standard_call_balance; |
|
660
|
|
|
$bal_data=$account_data[0]['balance']-$finaldeduct_bal; |
|
661
|
|
|
} |
|
662
|
|
|
$this->db->where("id", $response_arr['accountid']); |
|
663
|
|
|
$balance_data = array('balance' => $bal_data); |
|
|
|
|
|
|
664
|
|
|
$this->db->update("accounts", $balance_data); |
|
665
|
|
|
/*** invoice mail ***/ |
|
666
|
|
|
$this->invoice_send_notification($response_arr['invoiceid'],$account_data[0],'auto'); |
|
667
|
|
|
/***** ***/ |
|
668
|
|
|
} |
|
669
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Invoice updated successfully!'); |
|
670
|
|
|
redirect(base_url() . 'invoices/invoice_list/'); |
|
671
|
|
|
} |
|
672
|
|
|
|
|
673
|
|
|
/** |
|
674
|
|
|
* @param string $inv_flag |
|
675
|
|
|
*/ |
|
676
|
|
|
function invoice_send_notification($invoice_id,$accountdata,$inv_flag){ |
|
677
|
|
|
$invoicedata = $this->db_model->getSelect("*", "invoices", array("id" => $invoice_id)); |
|
678
|
|
|
$invoicedata = $invoicedata->result_array(); |
|
679
|
|
|
$invoicedata =$invoicedata[0]; |
|
680
|
|
|
//$res = $this->common->get_invoice_template($invoicedata,$accountdata,"False"); |
|
|
|
|
|
|
681
|
|
|
$invoice_conf = array(); |
|
682
|
|
View Code Duplication |
if($accountdata['reseller_id'] == 0){ |
|
683
|
|
|
$where = array("accountid"=> 1); |
|
684
|
|
|
} else{ |
|
685
|
|
|
$where = array("accountid"=> $accountdata['reseller_id']); |
|
686
|
|
|
} |
|
687
|
|
|
$query = $this->db_model->getSelect("*", "invoice_conf", $where); |
|
688
|
|
View Code Duplication |
if($query->num_rows >0){ |
|
689
|
|
|
$invoice_conf = $query->result_array(); |
|
690
|
|
|
$invoice_conf = $invoice_conf[0]; |
|
691
|
|
|
} else{ |
|
692
|
|
|
$query = $this->db_model->getSelect("*", "invoice_conf",array("accountid"=> 1)); |
|
693
|
|
|
$invoice_conf = $query->result_array(); |
|
694
|
|
|
$invoice_conf = $invoice_conf[0]; |
|
695
|
|
|
} |
|
696
|
|
|
$template_config=$this->config->item('invoice_screen'); |
|
697
|
|
|
include($template_config.'generateInvoice.php'); |
|
698
|
|
|
$generateInvoice = new generateInvoice(); |
|
699
|
|
|
$generateInvoice->download_invoice($invoicedata['id'],$accountdata,$invoice_conf,$inv_flag); |
|
|
|
|
|
|
700
|
|
|
return true; |
|
701
|
|
|
} |
|
702
|
|
|
function currency_decimal($amount){ |
|
703
|
|
|
$decimal_amount=Common_model::$global_config['system_config']['decimalpoints_total']; |
|
704
|
|
|
$number_convert=number_format((float)$amount,$decimal_amount, '.', ''); |
|
705
|
|
|
return $number_convert; |
|
706
|
|
|
} |
|
707
|
|
|
function invoice_summary($id){ |
|
708
|
|
|
$query="SELECT * from invoice_details where invoiceid='$id' "; |
|
709
|
|
|
|
|
710
|
|
|
$invoice_total_query=$this->db->query($query); |
|
711
|
|
|
if ($invoice_total_query ->num_rows() > 0) { |
|
712
|
|
|
$invoice_final_query = $invoice_total_query->result_array(); |
|
713
|
|
|
$data['invoice_final_query']=$invoice_final_query; |
|
|
|
|
|
|
714
|
|
|
|
|
715
|
|
|
$account_data = $this->session->userdata("accountinfo"); |
|
716
|
|
|
$logintype = $this->session->userdata('logintype'); |
|
717
|
|
|
$invoice_total=''; |
|
718
|
|
|
$query="SELECT * from invoice_details where item_type='INVPAY' AND invoiceid='$id' ORDER BY created_date ASC"; |
|
719
|
|
|
$invoice_total_query=$this->db->query($query); |
|
720
|
|
|
if ($invoice_total_query ->num_rows() > 0) { |
|
721
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
722
|
|
|
|
|
723
|
|
|
$data['invoice_total_query']=$invoice_total_query; |
|
724
|
|
|
} |
|
725
|
|
|
$invoice = $this->db_model->getSelect("*", "invoices", array("id"=> $id)); |
|
726
|
|
View Code Duplication |
if ($invoice ->num_rows() > 0) { |
|
727
|
|
|
$invoice= $invoice->result_array(); |
|
728
|
|
|
$result=$invoice[0]; |
|
729
|
|
|
$data['payment_due_date']=$result['due_date']; |
|
730
|
|
|
} |
|
731
|
|
|
|
|
732
|
|
|
$accountdata = $this->db_model->getSelect("*","accounts",array("id"=> $result['accountid'])); |
|
|
|
|
|
|
733
|
|
|
if ($accountdata ->num_rows() > 0) { |
|
734
|
|
|
$accountdata = $accountdata->result_array(); |
|
735
|
|
|
$accountdata = $accountdata[0]; |
|
736
|
|
|
} |
|
737
|
|
|
|
|
738
|
|
|
$system_config = common_model::$global_config['system_config']; |
|
739
|
|
View Code Duplication |
if($system_config["paypal_mode"]==0){ |
|
740
|
|
|
$data["paypal_url"] = $system_config["paypal_url"]; |
|
741
|
|
|
$data["paypal_email_id"] = $system_config["paypal_id"]; |
|
742
|
|
|
}else{ |
|
743
|
|
|
$data["paypal_url"] = $system_config["paypal_sandbox_url"]; |
|
744
|
|
|
$data["paypal_email_id"] = $system_config["paypal_sandbox_id"]; |
|
745
|
|
|
} |
|
746
|
|
|
$date = strtotime($result['invoice_date']); |
|
747
|
|
|
$data['time'] = date("Y-m-d h:i:s ",$date); |
|
748
|
|
|
$data["paypal_tax"] = $system_config["paypal_tax"]; |
|
749
|
|
|
$data["from_currency"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
750
|
|
|
$data["to_currency"] = Common_model::$global_config['system_config']['base_currency']; |
|
751
|
|
View Code Duplication |
if($account_data['type'] == -1){ |
|
752
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
753
|
|
|
$data["to_currency"] = $accountdata["currency_id"]; |
|
754
|
|
|
}elseif($account_data['type'] == 1){ |
|
755
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
756
|
|
|
$data["to_currency"] = $accountdata["currency_id"]; |
|
757
|
|
|
}else{ |
|
758
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $account_data["currency_id"]); |
|
759
|
|
|
$data["to_currency"] = $accountdata["currency_id"]; |
|
760
|
|
|
} |
|
761
|
|
|
$data["system_currency"] = Common_model::$global_config['system_config']['base_currency']; |
|
762
|
|
|
foreach($invoice_total_query as $value){ |
|
763
|
|
|
$data['from_date']=$result['from_date']; |
|
764
|
|
|
$data['to_date']=$result['to_date']; |
|
765
|
|
|
$data['invoice_date']=$result['invoice_date']; |
|
766
|
|
|
$data['amount'] = $this->common_model->calculate_currency($result['amount']); |
|
767
|
|
|
$data['invoice_prefix'] = $result['invoice_prefix']; |
|
768
|
|
|
$data['page_title'] = 'Invoice Summary'; |
|
769
|
|
|
$data['invoice_date']=$result['invoice_date']; |
|
770
|
|
|
$data['return'] =base_url() . "invoices/invoice_list_modified"; |
|
771
|
|
|
$data['cancel_return'] =base_url()."invoice/invoice_list_cancel"; |
|
772
|
|
|
$data['paypal_mode'] = 1; |
|
773
|
|
|
$data['prefix_id']=$result['invoiceid']; |
|
774
|
|
|
$data['logintype']=$logintype; |
|
775
|
|
|
$data['accountdata'] = $accountdata; |
|
776
|
|
|
$data['value']=$value; |
|
777
|
|
|
$data['id']=$id; |
|
778
|
|
|
$data['notify_url'] = base_url() . "invoices/invoice_list_get_data/"; |
|
779
|
|
View Code Duplication |
if($account_data['type'] =='1'){ |
|
780
|
|
|
$data['response_url'] = base_url() . "invoices/invoice_list_responce/"; |
|
781
|
|
|
}else{ |
|
782
|
|
|
$data['response_url'] = base_url() . "user/user_list_responce/"; |
|
783
|
|
|
} |
|
784
|
|
|
$data['sucess_url'] = base_url() . "invoices/invoice_list_sucess/"; |
|
785
|
|
|
} |
|
786
|
|
|
|
|
787
|
|
|
}else{ |
|
788
|
|
|
|
|
789
|
|
|
redirect(base_url() . 'dashboard/'); |
|
790
|
|
|
} |
|
791
|
|
|
$this->load->view('view_invoice_payment',$data); |
|
|
|
|
|
|
792
|
|
|
} |
|
793
|
|
|
function invoice_list_get_data(){ |
|
794
|
|
|
redirect(base_url().'invoices/invoice_list/'); |
|
795
|
|
|
} |
|
796
|
|
|
function convert_amount($amount){ |
|
797
|
|
|
$amount = $this->common_model->add_calculate_currency($amount,"","",true,false); |
|
798
|
|
|
echo number_format($amount,2); |
|
799
|
|
|
} |
|
800
|
|
|
function invoice_list_responce(){ |
|
801
|
|
|
$response_arr=$_POST; |
|
802
|
|
|
$logintype = $this->session->userdata('logintype'); |
|
803
|
|
|
if( ($response_arr["payment_status"] == "Pending" || $response_arr["payment_status"] == "Complete" || $response_arr["payment_status"] == "Completed" ) ){ |
|
804
|
|
|
$invoice_id=$response_arr['item_number']; |
|
805
|
|
|
$amount=$response_arr['payment_gross']; |
|
806
|
|
|
$description=$response_arr['item_name']; |
|
807
|
|
|
$debit=''; |
|
808
|
|
|
|
|
809
|
|
|
$paypal_tax = $this->db_model->getSelect("value", "system", array("name" => "paypal_tax","group_title"=>"paypal")); |
|
810
|
|
|
$paypal_tax = $paypal_tax->result(); |
|
811
|
|
|
$paypal_tax = $paypal_tax[0]->value; |
|
812
|
|
|
$balance_amt = $actual_amount = $response_arr["custom"]; |
|
813
|
|
|
|
|
814
|
|
|
$paypal_fee = $this->db_model->getSelect("value", "system", array("name" => "paypal_fee","group_title"=>"paypal")); |
|
815
|
|
|
$paypal_fee = $paypal_fee->result(); |
|
816
|
|
|
$paypal_fee = $paypal_fee[0]->value; |
|
817
|
|
|
|
|
818
|
|
|
$paypalfee = ($paypal_fee == 0)?'0':$response_arr["mc_gross"]; |
|
819
|
|
|
|
|
820
|
|
|
$account_data = $this->db_model->getSelect("*", "accounts", array("id" => $response_arr["custom"])); |
|
821
|
|
|
$account_data = $account_data->result_array(); |
|
822
|
|
|
$account_data = $account_data[0]; |
|
823
|
|
|
$currency = $this->db_model->getSelect('currency,currencyrate', 'currency', array("id"=>$account_data["currency_id"])); |
|
824
|
|
|
$currency = $currency->result_array(); |
|
825
|
|
|
$currency =$currency[0]; |
|
826
|
|
|
$date = date('Y-m-d H:i:s'); |
|
827
|
|
|
$invoice_total_query = $this->db_model->getSelect("*", "invoices", array("id"=> $invoice_id)); |
|
828
|
|
View Code Duplication |
if ( $invoice_total_query ->num_rows() > 0) { |
|
829
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
830
|
|
|
$debit=$invoice_total_query[0]['amount']; |
|
831
|
|
|
} |
|
832
|
|
|
$query="select sum(credit) as credit from invoice_details where invoiceid = ".$invoice_id." AND item_type !='PAYMENT' Group By invoiceid"; |
|
833
|
|
|
//echo $query; exit; |
|
|
|
|
|
|
834
|
|
|
$invoice_total_query=$this->db->query($query); |
|
835
|
|
View Code Duplication |
if ($invoice_total_query ->num_rows() > 0) { |
|
836
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
837
|
|
|
$total_debit=$invoice_total_query[0]['credit']; |
|
838
|
|
|
} |
|
839
|
|
|
$credit_total=$total_debit+$amount; |
|
|
|
|
|
|
840
|
|
|
// echo $debit; exit; |
|
|
|
|
|
|
841
|
|
|
if($debit >= $credit_total) { |
|
842
|
|
|
|
|
843
|
|
|
|
|
844
|
|
View Code Duplication |
if($debit == $credit_total){ |
|
845
|
|
|
|
|
846
|
|
|
$this->db->where("id", $invoice_id); |
|
847
|
|
|
$data = array('status' => '0'); |
|
848
|
|
|
$this->db->update("invoices", $data); |
|
849
|
|
|
// echo $this->db->last_query(); exit; |
|
|
|
|
|
|
850
|
|
|
}else{ |
|
851
|
|
|
$this->db->where("id", $invoice_id); |
|
852
|
|
|
$data = array('status' => '2'); |
|
853
|
|
|
$this->db->update("invoices", $data); |
|
854
|
|
|
// echo $this->db->last_query(); exit; |
|
|
|
|
|
|
855
|
|
|
} |
|
856
|
|
|
|
|
857
|
|
View Code Duplication |
if($amount > $debit){ |
|
858
|
|
|
$this->session->set_flashdata('astpp_notification', 'Invoice payment amount should be higher then the invoice amount.'); |
|
859
|
|
|
redirect(base_url().'invoices/invoice_summary/'.$invoice_id); |
|
860
|
|
|
} |
|
861
|
|
|
$payment_trans_array = array("accountid"=>$response_arr["custom"],"amount"=>$response_arr["payment_gross"], |
|
862
|
|
|
"tax"=>"1","payment_method"=>"Paypal","actual_amount"=> $amount,"paypal_fee"=> $paypalfee, |
|
863
|
|
|
"user_currency"=>$currency["currency"],"currency_rate"=>$currency["currencyrate"],"transaction_details"=>json_encode($response_arr),"date"=>$date); |
|
864
|
|
|
$this->db->insert('payment_transaction',$payment_trans_array); |
|
865
|
|
|
$transaction_details_id= $this->db->insert_id(); |
|
866
|
|
|
|
|
867
|
|
|
|
|
868
|
|
|
if($transaction_details_id == ''){ |
|
869
|
|
|
$transaction_details_id == 0; |
|
870
|
|
|
} |
|
871
|
|
|
|
|
872
|
|
|
$accountdata = $this->db_model->getSelect("*","payment_transaction",array()); |
|
873
|
|
|
if($accountdata->num_rows() > 0){ |
|
874
|
|
|
foreach($accountdata->result_array() as $payment_value){ |
|
875
|
|
|
$payment_transaction=$payment_value['transaction_details']; |
|
876
|
|
|
$payment_result=json_decode($payment_transaction,true); |
|
877
|
|
|
$transaction_id= $payment_result['txn_id']; |
|
878
|
|
|
} |
|
879
|
|
|
} |
|
880
|
|
|
$invoice_total_history = $this->db_model->getSelect("*", "invoice_details", array("invoiceid"=> $invoice_id,'item_type'=>'INVPAY')); |
|
881
|
|
|
$account_balance=$account_data['balance']; |
|
882
|
|
|
if ($invoice_total_history ->num_rows() > 0) { |
|
883
|
|
|
// echo 'if'; exit; |
|
|
|
|
|
|
884
|
|
|
$invoice_main= $invoice_total_history->result_array(); |
|
885
|
|
|
// echo '<pre>'; print_r($invoice_main); exit; |
|
|
|
|
|
|
886
|
|
|
$debit_amount = "0.00"; |
|
887
|
|
|
foreach($invoice_main as $value){ |
|
888
|
|
|
$debit_amount = $value['debit']; |
|
889
|
|
|
} |
|
890
|
|
|
|
|
891
|
|
|
$actual_amount= $debit_amount-$amount; |
|
892
|
|
|
// echo $actual_amount; exit; |
|
|
|
|
|
|
893
|
|
|
$tax_array = array("accountid"=>$response_arr["custom"],"invoiceid"=>$invoice_id,"item_id"=> $transaction_details_id,"description"=>$description,"debit"=>$this->common->currency_decimal(0),"credit"=> $this->common->currency_decimal($amount),"item_type"=>"INVPAY","created_date"=> $date,"reseller_id"=>$account_data['reseller_id'],'before_balance'=>$account_balance,'after_balance'=>$account_balance+$amount, |
|
894
|
|
|
); // echo '<pre>'; print_r( $tax_array); exit; |
|
|
|
|
|
|
895
|
|
|
$this->db->insert("invoice_details",$tax_array); |
|
896
|
|
|
|
|
897
|
|
|
}else{ |
|
898
|
|
|
|
|
899
|
|
|
// echo 'else'; exit; |
|
|
|
|
|
|
900
|
|
|
$actual_amount=$debit-$amount; |
|
901
|
|
|
$tax_array = array("accountid"=>$response_arr["custom"],"invoiceid"=>$invoice_id,"item_id"=> $transaction_details_id,"description"=>$description,"debit"=> $this->common->currency_decimal(0),"credit"=> $this->common->currency_decimal($amount),"item_type"=>"INVPAY","created_date"=> $date,"reseller_id"=>$account_data['reseller_id'],'before_balance'=>$account_balance,'after_balance'=>$account_balance+$amount); |
|
902
|
|
|
|
|
903
|
|
|
$this->db->insert("invoice_details",$tax_array); |
|
904
|
|
|
} |
|
905
|
|
View Code Duplication |
}else{ |
|
906
|
|
|
if($logintype = 0){ |
|
907
|
|
|
$this->session->set_flashdata('astpp_notification', 'Invoice payment amount should be higher then the invoice amount.'); |
|
908
|
|
|
redirect(base_url().'user/user_invoice_payment/'.$invoice_id); |
|
909
|
|
|
}else{ |
|
910
|
|
|
$this->session->set_flashdata('astpp_notification', 'Invoice payment amount should be higher then the invoice amount.'); |
|
911
|
|
|
redirect(base_url().'invoices/invoice_summary/'.$invoice_id); |
|
912
|
|
|
} |
|
913
|
|
|
|
|
914
|
|
|
} |
|
915
|
|
|
|
|
916
|
|
|
$this->load->module('accounts/accounts'); |
|
917
|
|
|
$reseller_debit=0; |
|
918
|
|
|
$reseller_debit=$this->common->get_field_name('reseller_id', 'accounts', array('id'=>$response_arr["custom"],'status'=>0,'deleted'=>0)); |
|
919
|
|
|
// echo '<pre>'; print_r($reseller_debit); exit; |
|
|
|
|
|
|
920
|
|
|
if($reseller_debit > 0){ |
|
921
|
|
|
$this->accounts_model->update_balance($amount,$response_arr["custom"], "debit"); |
|
922
|
|
|
$this->accounts_model->update_balance($amount,$reseller_debit, "debit"); |
|
923
|
|
|
} else{ |
|
924
|
|
|
$this->accounts_model->update_balance($amount,$response_arr["custom"], "debit"); |
|
925
|
|
|
} |
|
926
|
|
|
$account_data['accountid']=$account_data['id']; |
|
927
|
|
|
$this->email_lib->send_email('email_payment_notification',$account_data ,'','',0,0,0); |
|
928
|
|
View Code Duplication |
if($logintype = '1'){ |
|
929
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Invoice payment done successfully!'); |
|
930
|
|
|
redirect(base_url() . 'invoices/invoice_list/'); |
|
931
|
|
|
}else{ |
|
932
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Invoice payment done successfully!'); |
|
933
|
|
|
redirect(base_url() . 'user/user_invoices_list/'); |
|
934
|
|
|
} |
|
935
|
|
|
} |
|
936
|
|
|
} |
|
937
|
|
|
function invoice_admin_payment(){ |
|
938
|
|
|
|
|
939
|
|
|
$response_arr=$_POST; |
|
940
|
|
|
|
|
941
|
|
|
if(!empty($response_arr)){ |
|
942
|
|
|
|
|
943
|
|
|
$amount=$response_arr['amount']; |
|
944
|
|
|
$description=$response_arr['item_name']; |
|
945
|
|
|
$invoice_id=$response_arr['item_number']; |
|
946
|
|
|
$date = date('Y-m-d H:i:s'); |
|
947
|
|
|
|
|
948
|
|
|
$invoice_total_query = $this->db_model->getSelect("*", "invoices", array("id"=> $invoice_id)); |
|
949
|
|
View Code Duplication |
if ( $invoice_total_query ->num_rows() > 0) { |
|
950
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
951
|
|
|
$debit=$invoice_total_query[0]['amount']; |
|
952
|
|
|
} |
|
953
|
|
|
|
|
954
|
|
|
$query="select sum(credit) as credit from invoice_details where invoiceid = ".$invoice_id." AND item_type !='PAYMENT' Group By invoiceid"; |
|
955
|
|
|
//echo $query; exit; |
|
|
|
|
|
|
956
|
|
|
$invoice_total_query=$this->db->query($query); |
|
957
|
|
View Code Duplication |
if ($invoice_total_query ->num_rows() > 0) { |
|
958
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
959
|
|
|
$total_debit=$invoice_total_query[0]['credit']; |
|
960
|
|
|
} |
|
961
|
|
|
$credit_total=$total_debit+$amount; |
|
|
|
|
|
|
962
|
|
|
// echo $credit_total; exit; |
|
|
|
|
|
|
963
|
|
|
if($debit >= $credit_total) { |
|
964
|
|
|
|
|
965
|
|
|
|
|
966
|
|
View Code Duplication |
if($debit == $credit_total){ |
|
|
|
|
|
|
967
|
|
|
|
|
968
|
|
|
$this->db->where("id", $invoice_id); |
|
969
|
|
|
$data = array('status' => '0'); |
|
970
|
|
|
$this->db->update("invoices", $data); |
|
971
|
|
|
// echo $this->db->last_query(); exit; |
|
|
|
|
|
|
972
|
|
|
}else{ |
|
973
|
|
|
$this->db->where("id", $invoice_id); |
|
974
|
|
|
$data = array('status' => '2'); |
|
975
|
|
|
$this->db->update("invoices", $data); |
|
976
|
|
|
// echo $this->db->last_query(); exit; |
|
|
|
|
|
|
977
|
|
|
} |
|
978
|
|
|
|
|
979
|
|
View Code Duplication |
if($amount > $debit){ |
|
980
|
|
|
$this->session->set_flashdata('astpp_notification', 'Invoice payment amount should be higher then the invoice amount.'); |
|
981
|
|
|
redirect(base_url().'invoices/invoice_summary/'.$invoice_id); |
|
982
|
|
|
} |
|
983
|
|
|
|
|
984
|
|
|
|
|
985
|
|
|
$debit_amount = "0.00"; |
|
986
|
|
|
$account_balance = $this->common->get_field_name('balance', 'accounts', $response_arr['custom']); |
|
987
|
|
|
$tax_array = array("accountid"=>$response_arr["custom"],"invoiceid"=>$invoice_id,"item_id"=> '',"description"=>$description,"debit"=>"0.00","credit"=> $amount,"item_type"=>"INVPAY","created_date"=> $date,"reseller_id"=>"0",'before_balance'=>$account_balance,'after_balance'=>$account_balance+$amount); |
|
988
|
|
|
$this->db->insert("invoice_details",$tax_array); |
|
989
|
|
|
|
|
990
|
|
|
|
|
991
|
|
|
}else{ |
|
992
|
|
|
|
|
993
|
|
|
$this->session->set_flashdata('astpp_notification', 'Invoice payment amount should be higher then the invoice amount.'); |
|
994
|
|
|
redirect(base_url().'invoices/invoice_summary/'.$invoice_id); |
|
995
|
|
|
} |
|
996
|
|
|
|
|
997
|
|
|
$this->load->module('accounts/accounts'); |
|
998
|
|
|
$this->accounts_model->update_balance($amount,$response_arr["custom"], "debit"); |
|
999
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Invoice payment done successfully!'); |
|
1000
|
|
|
|
|
1001
|
|
|
} |
|
1002
|
|
|
$account_data = $this->db_model->getSelect("*", "accounts", array("id" => $response_arr["custom"])); |
|
1003
|
|
|
$account_data = $account_data->result_array(); |
|
1004
|
|
|
$account_data = $account_data[0]; |
|
1005
|
|
|
$account_data['accountid']=$account_data['id']; |
|
1006
|
|
|
// $this->email_lib->send_email('email_payment_notification',$account_data ,'','',0,0,0); |
|
|
|
|
|
|
1007
|
|
|
redirect(base_url() . 'invoices/invoice_list/'); |
|
1008
|
|
|
|
|
1009
|
|
|
} |
|
1010
|
|
|
|
|
1011
|
|
|
function invoice_list_sucess(){ |
|
1012
|
|
|
echo 'sucess'; exit; |
|
1013
|
|
|
|
|
1014
|
|
|
} |
|
1015
|
|
|
function invoice_list_modified(){ |
|
1016
|
|
|
echo 'sucess'; exit; |
|
1017
|
|
|
|
|
1018
|
|
|
} |
|
1019
|
|
|
|
|
1020
|
|
|
function invoice_delete(){ |
|
1021
|
|
|
$ids = $this->input->post("selected_ids", true); |
|
1022
|
|
|
$where = "id IN ($ids)"; |
|
1023
|
|
|
$this->db->where($where); |
|
1024
|
|
|
echo $this->db->delete("invoices"); |
|
1025
|
|
|
} |
|
1026
|
|
|
|
|
1027
|
|
|
function invoice_conf() { |
|
1028
|
|
|
$data['page_title'] = 'Company Profile'; |
|
|
|
|
|
|
1029
|
|
|
$post_array = $this->input->post(); |
|
1030
|
|
|
$accountinfo=$this->session->userdata('accountinfo'); |
|
1031
|
|
|
unset($post_array['action']); |
|
1032
|
|
|
unset($post_array['button']); |
|
1033
|
|
|
unset($post_array['file']); |
|
1034
|
|
|
|
|
1035
|
|
|
if (!empty($post_array)) { |
|
1036
|
|
|
$invoice_prefix = trim($post_array['invoice_prefix']); |
|
1037
|
|
View Code Duplication |
if ($_FILES['file']['name'] == '') { |
|
1038
|
|
|
$invoiceconf = $this->invoices_model->get_invoiceconf($post_array['accountid']); |
|
1039
|
|
|
$file_name=($invoiceconf['logo'] != '') ? $invoiceconf['logo'] : ''; |
|
1040
|
|
|
} |
|
1041
|
|
|
if ($invoice_prefix == '') { |
|
1042
|
|
|
$this->session->set_flashdata('astpp_notification', 'Invoice Prefix is required.'); |
|
1043
|
|
|
redirect(base_url() . 'invoices/invoice_conf/'); |
|
1044
|
|
|
} |
|
1045
|
|
|
|
|
1046
|
|
|
if (isset($_FILES['file']['name']) && $_FILES['file']['name'] != '') { |
|
1047
|
|
|
$files = $_FILES['file']; |
|
1048
|
|
|
if ($files['size'] < 0) { |
|
1049
|
|
|
$this->session->set_flashdata('astpp_notification', 'PLease upload maximum file'); |
|
1050
|
|
|
redirect(base_url() . 'invoices/invoice_conf/'); |
|
1051
|
|
|
} |
|
1052
|
|
|
$file = $_FILES['file']; |
|
1053
|
|
|
$uploadedFile = $file["tmp_name"]; |
|
1054
|
|
|
$file_name = $file['name']; |
|
1055
|
|
|
$file_type = $file['type']; |
|
1056
|
|
View Code Duplication |
if ($file_type == 'image/jpg' || $file_type == 'image/png' || $file_type == 'image/jpeg') { |
|
1057
|
|
|
$dir_path = FCPATH. "upload/"; |
|
1058
|
|
|
$path = $dir_path . $accountinfo['id']."_".$file['name']; |
|
1059
|
|
|
if (move_uploaded_file($uploadedFile, $path)) { |
|
1060
|
|
|
$this->session->set_flashdata('astpp_errormsg', gettext('files added successfully!')); |
|
1061
|
|
|
} else { |
|
1062
|
|
|
$this->session->set_flashdata('astpp_notification', "File Uploading Fail Please Try Again"); |
|
1063
|
|
|
redirect(base_url() . 'invoices/invoice_conf/'); |
|
1064
|
|
|
} |
|
1065
|
|
|
} else { |
|
1066
|
|
|
$this->session->set_flashdata('astpp_notification', 'Please upload only image!'); |
|
1067
|
|
|
redirect(base_url() . 'invoices/invoice_conf/'); |
|
1068
|
|
|
} |
|
1069
|
|
|
} |
|
1070
|
|
|
$post_array['logo'] = $file_name; |
|
|
|
|
|
|
1071
|
|
|
|
|
1072
|
|
|
$this->invoices_model->save_invoiceconf($post_array); |
|
1073
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Invoice configuration updated sucessfully!'); |
|
1074
|
|
|
redirect(base_url() . 'invoices/invoice_conf/'); |
|
1075
|
|
|
} else { |
|
1076
|
|
|
|
|
1077
|
|
|
$invoiceconf = $this->invoices_model->get_invoiceconf($accountinfo['id']); |
|
1078
|
|
|
|
|
1079
|
|
|
if (!empty($invoiceconf)) { |
|
1080
|
|
|
$data['file_name'] = $accountinfo['id']."_".$invoiceconf['logo']; |
|
1081
|
|
|
$invoiceconf['file']=$accountinfo['id']."_".$invoiceconf['logo']; |
|
1082
|
|
|
} |
|
1083
|
|
|
|
|
1084
|
|
|
$data['form'] = $this->form->build_form($this->invoices_form->get_invoiceconf_form_fields($invoiceconf), $invoiceconf); |
|
1085
|
|
|
|
|
1086
|
|
|
$this->load->view('view_invoiceconf', $data); |
|
1087
|
|
|
} |
|
1088
|
|
|
} |
|
1089
|
|
|
function incr($inteval){ |
|
1090
|
|
|
$inteval++; // $a is undefined |
|
1091
|
|
|
return $inteval; |
|
1092
|
|
|
} |
|
1093
|
|
|
|
|
1094
|
|
|
|
|
1095
|
|
|
function customer_invoices($accountid){ |
|
1096
|
|
|
// echo '<pre>'; print_r($accountid); exit; |
|
|
|
|
|
|
1097
|
|
|
$json_data = array(); |
|
1098
|
|
|
/**** |
|
1099
|
|
|
Invoice manually |
|
1100
|
|
|
**/ |
|
1101
|
|
|
$where = array('accountid' => $accountid,'confirm'=>1); |
|
1102
|
|
|
$count_all = $this->db_model->countQuery("*","invoices",$where); |
|
1103
|
|
|
$currency_id = Common_model::$global_config['system_config']['base_currency']; |
|
1104
|
|
|
$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
|
1105
|
|
|
$json_data = $paging_data["json_paging"]; |
|
1106
|
|
|
|
|
1107
|
|
|
$Invoice_grid_data = $this->db_model->select("*","invoices",$where,"invoice_date","desc",$paging_data["paging"]["page_no"],$paging_data["paging"]["start"]); |
|
1108
|
|
|
// echo $this->db->last_query(); exit; |
|
|
|
|
|
|
1109
|
|
|
$grid_fields= json_decode($this->invoices_form->build_invoices_list_for_admin()); |
|
1110
|
|
|
|
|
1111
|
|
|
// $json_data['rows'] = $this->form->build_grid($Invoice_grid_data,$grid_fields); |
|
|
|
|
|
|
1112
|
|
|
$logintype = $this->session->userdata('logintype'); |
|
1113
|
|
|
$url= ($logintype==0 ||$logintype==3 ) ? "/user/user_invoice_download/":'/invoices/invoice_download/'; |
|
1114
|
|
|
if($Invoice_grid_data->num_rows > 0 ){ |
|
1115
|
|
|
$query=$Invoice_grid_data->result_array(); |
|
1116
|
|
|
$total_value = 0; |
|
1117
|
|
|
$ountstanding_value = 0; |
|
1118
|
|
|
|
|
1119
|
|
|
foreach ($query as $key => $value) { |
|
1120
|
|
|
$date = strtotime($value['invoice_date']); |
|
1121
|
|
|
$invoice_date =date("Y-m-d",$date); |
|
1122
|
|
|
$fromdate = strtotime($value['from_date']); |
|
1123
|
|
|
$from_date =date("Y-m-d",$fromdate); |
|
1124
|
|
|
$duedate = strtotime($value['due_date']); |
|
1125
|
|
|
$due_date =date("Y-m-d",$duedate); |
|
1126
|
|
|
$outstanding = $value['amount']; |
|
1127
|
|
|
$last_payment_date = ''; |
|
1128
|
|
|
$invoice_total_query = $this->db_model->select("sum(debit) as debit,sum(credit) as credit,created_date", "invoice_details", array("invoiceid"=> $value['id'],"item_type"=>"INVPAY"),"created_date","DESC","1","0"); |
|
1129
|
|
|
// echo $this->db->last_query(); exit; |
|
|
|
|
|
|
1130
|
|
View Code Duplication |
if ($invoice_total_query ->num_rows() > 0){ |
|
1131
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
1132
|
|
|
//echo '<pre>'; print_r($invoice_total_query); |
|
|
|
|
|
|
1133
|
|
|
$outstanding -= $invoice_total_query[0]['credit']; |
|
1134
|
|
|
|
|
1135
|
|
|
$last_payment_date = $invoice_total_query[0]['created_date']; |
|
1136
|
|
|
if($last_payment_date ){ |
|
1137
|
|
|
$payment_date=strtotime( $last_payment_date); |
|
1138
|
|
|
$payment_last=date("d/m/Y",$payment_date); |
|
1139
|
|
|
}else{ |
|
1140
|
|
|
$payment_last=''; |
|
1141
|
|
|
} |
|
1142
|
|
|
|
|
1143
|
|
|
|
|
1144
|
|
|
} |
|
1145
|
|
|
$invoice_total=''; |
|
1146
|
|
|
$accountinfo=$this->session->userdata('accountinfo'); |
|
1147
|
|
|
$id=$accountinfo['id']; |
|
1148
|
|
|
$query ="select sum(amount) as grand_total from invoices where confirm=1 and accountid=$accountid"; |
|
1149
|
|
|
|
|
1150
|
|
|
$ext_query=$this->db->query($query); |
|
1151
|
|
View Code Duplication |
if($ext_query->num_rows() > 0){ |
|
1152
|
|
|
$result_total=$ext_query->result_array(); |
|
1153
|
|
|
$grandtotal=$result_total[0]['grand_total']; |
|
1154
|
|
|
$grand_total=$this->common->currency_decimal($grandtotal).' '.$currency_id; |
|
1155
|
|
|
} |
|
1156
|
|
|
|
|
1157
|
|
|
$invoice_query ="select sum(credit) as grand_credit from invoice_details where accountid=$accountid"; |
|
1158
|
|
|
$credit_query=$this->db->query($invoice_query); |
|
1159
|
|
View Code Duplication |
if($credit_query->num_rows() > 0){ |
|
1160
|
|
|
$credit_total=$credit_query->result_array(); |
|
1161
|
|
|
$grand_credit_total=$credit_total[0]['grand_credit']; |
|
1162
|
|
|
$grandcredit=$grand_total-$grand_credit_total; |
|
|
|
|
|
|
1163
|
|
|
$grand_credit=$this->common->currency_decimal($grandcredit).' '.$currency_id; |
|
1164
|
|
|
} |
|
1165
|
|
|
|
|
1166
|
|
|
|
|
1167
|
|
|
|
|
1168
|
|
|
$download="<a href=" . $url .$value['id']. " class='btn btn-royelblue btn-sm' title='Download Invoice' ><i class='fa fa-cloud-download fa-fw'></i></a> "; |
|
1169
|
|
View Code Duplication |
if($value['type'] == 'R'){ |
|
1170
|
|
|
$payment =''; |
|
1171
|
|
|
$outstanding=0; |
|
1172
|
|
|
}else{ |
|
1173
|
|
|
if($outstanding > 0){ |
|
1174
|
|
|
$payment = '<a style="padding: 0 8px;" href="'. base_url() .'invoices/invoice_summary/' . $value['id'] . '" class="btn btn-warning" title="Payment">Unpaid</i></a>'; |
|
1175
|
|
|
}else{ |
|
1176
|
|
|
$payment = ' <button style="padding: 0 8px;" type="button" class="btn btn-success">Paid</button>'; |
|
1177
|
|
|
} |
|
1178
|
|
|
} |
|
1179
|
|
|
|
|
1180
|
|
|
$account_arr = $this->db_model->getSelect('first_name,number,last_name','accounts', array('id'=>$value['accountid'])); |
|
1181
|
|
|
$account_array = $account_arr->result_array(); |
|
1182
|
|
|
if($value['generate_type'] == 1){ |
|
1183
|
|
|
$invoice_type='Manually'; |
|
1184
|
|
|
} else{ |
|
1185
|
|
|
$invoice_type='Automatically'; |
|
1186
|
|
|
} |
|
1187
|
|
|
|
|
1188
|
|
|
if($value['type'] == 'R'){ |
|
1189
|
|
|
$icon = '<div class="flx_font flx_magenta">R</div>'; |
|
1190
|
|
|
} else |
|
1191
|
|
|
{ |
|
1192
|
|
|
$icon = '<div class="flx_font flx_drk_pink">I</div>'; |
|
1193
|
|
|
|
|
1194
|
|
|
} |
|
1195
|
|
|
|
|
1196
|
|
|
|
|
1197
|
|
|
$json_data['rows'][] = array('cell' => array( |
|
1198
|
|
|
$value['invoice_prefix'].$value['invoiceid'].$icon, |
|
1199
|
|
|
//$value['invoice_prefix'].$value['invoiceid'].' ('.$value['type'].')', |
|
|
|
|
|
|
1200
|
|
|
$invoice_type, |
|
1201
|
|
|
// $account_array[0]['first_name'].' '.$account_array[0]['last_name'].'</br>'.$account_array[0]['number'], |
|
|
|
|
|
|
1202
|
|
|
$invoice_date, |
|
1203
|
|
|
$from_date, |
|
1204
|
|
|
$due_date, |
|
1205
|
|
|
$payment_last, |
|
|
|
|
|
|
1206
|
|
|
$this->common_model->to_calculate_currency($value['amount'], '', '', true, false), |
|
1207
|
|
|
$this->common_model->to_calculate_currency($outstanding, '', '', true, false), |
|
1208
|
|
|
$download.''.$payment, |
|
1209
|
|
|
)); |
|
1210
|
|
|
$total_value=$total_value + $value['amount']; |
|
1211
|
|
|
$ountstanding_value=$ountstanding_value + $outstanding; |
|
1212
|
|
|
} |
|
1213
|
|
|
} |
|
1214
|
|
|
|
|
1215
|
|
|
echo json_encode($json_data); |
|
1216
|
|
|
} |
|
1217
|
|
|
function user_invoices($accountid){ |
|
1218
|
|
|
$json_data = array(); |
|
1219
|
|
|
$count_all = $this->invoices_model->get_user_invoice_list(false); |
|
1220
|
|
|
$paging_data = $this->form->load_grid_config($count_all, $_GET['rp'], $_GET['page']); |
|
1221
|
|
|
$json_data = $paging_data["json_paging"]; |
|
1222
|
|
|
$currency_id = Common_model::$global_config['system_config']['base_currency']; |
|
1223
|
|
|
$query = $this->invoices_model->get_user_invoice_list(true,$paging_data["paging"]["start"], $paging_data["paging"]["page_no"]); |
|
1224
|
|
|
$grid_fields= json_decode($this->invoices_form->build_invoices_list_for_customer()); |
|
1225
|
|
|
$query=$query->result_array(); |
|
1226
|
|
|
$account_arr = ''; |
|
1227
|
|
|
$created_date=''; |
|
1228
|
|
|
foreach ($query as $key => $value) { |
|
1229
|
|
|
$date = strtotime($value['invoice_date']); |
|
1230
|
|
|
$invoice_date =date("d/m/Y",$date); |
|
1231
|
|
|
$fromdate = strtotime($value['from_date']); |
|
1232
|
|
|
$from_date =date("d/m/Y",$fromdate); |
|
1233
|
|
|
$duedate = strtotime($value['due_date']); |
|
1234
|
|
|
$due_date =date("d/m/Y",$duedate); |
|
1235
|
|
|
$outstanding = $value['amount']; |
|
1236
|
|
|
$invoice_total_query = $this->db_model->select("sum(debit) as debit,sum(credit) as credit,created_date", "invoice_details", array("invoiceid"=> $value['id'],"item_type"=>"INVPAY"),"created_date","DESC","1","0"); |
|
1237
|
|
|
// echo $this->db->last_query(); exit; |
|
|
|
|
|
|
1238
|
|
View Code Duplication |
if ($invoice_total_query ->num_rows() > 0){ |
|
1239
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
1240
|
|
|
//echo '<pre>'; print_r($invoice_total_query); |
|
|
|
|
|
|
1241
|
|
|
$outstanding -= $invoice_total_query[0]['credit']; |
|
1242
|
|
|
|
|
1243
|
|
|
$last_payment_date = $invoice_total_query[0]['created_date']; |
|
1244
|
|
|
if($last_payment_date ){ |
|
1245
|
|
|
$payment_date=strtotime( $last_payment_date); |
|
1246
|
|
|
$payment_last=date("d/m/Y",$payment_date); |
|
1247
|
|
|
}else{ |
|
1248
|
|
|
$payment_last=''; |
|
1249
|
|
|
} |
|
1250
|
|
|
|
|
1251
|
|
|
|
|
1252
|
|
|
} |
|
1253
|
|
|
$invoice_total_query = $this->db_model->select("debit,created_date", "invoice_details", array("invoiceid"=> $value['id'],"item_type"=>"INVPAY"),"created_date","DESC","1","0"); |
|
1254
|
|
|
if ( $invoice_total_query ->num_rows() > 0) { |
|
1255
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
1256
|
|
|
// $outstanding = $invoice_total_query[0]['debit']; |
|
|
|
|
|
|
1257
|
|
|
$created_date = $invoice_total_query[0]['created_date']; |
|
1258
|
|
|
} |
|
1259
|
|
|
$accountinfo=$this->session->userdata('accountinfo'); |
|
1260
|
|
|
$query ="select sum(amount) as grand_total from invoices where confirm=1 and accountid=$accountid"; |
|
1261
|
|
|
|
|
1262
|
|
|
$ext_query=$this->db->query($query); |
|
1263
|
|
View Code Duplication |
if($ext_query->num_rows() > 0){ |
|
1264
|
|
|
$result_total=$ext_query->result_array(); |
|
1265
|
|
|
$grandtotal=$result_total[0]['grand_total']; |
|
1266
|
|
|
$grand_total=$this->common->currency_decimal($grandtotal).' '.$currency_id; |
|
1267
|
|
|
} |
|
1268
|
|
|
|
|
1269
|
|
|
$invoice_query ="select sum(credit) as grand_credit from invoice_details where accountid=$accountid"; |
|
1270
|
|
|
$credit_query=$this->db->query($invoice_query); |
|
1271
|
|
View Code Duplication |
if($credit_query->num_rows() > 0){ |
|
1272
|
|
|
$credit_total=$credit_query->result_array(); |
|
1273
|
|
|
$grand_credit_total=$credit_total[0]['grand_credit']; |
|
1274
|
|
|
$grandcredit=$grand_total-$grand_credit_total; |
|
|
|
|
|
|
1275
|
|
|
$grand_credit=$this->common->currency_decimal($grandcredit).' '.$currency_id; |
|
1276
|
|
|
} |
|
1277
|
|
|
$download='<a href="'. base_url() .'/user/user_invoice_download/' . $value['id'].'/00'.$value['invoice_prefix'].$value['invoiceid'].'" class="btn btn-royelblue btn-sm" title="Download Invoice" ><i class="fa fa-cloud-download fa-fw"></i></a> '; |
|
1278
|
|
|
if($outstanding > 0){ |
|
1279
|
|
|
$payment = ' <a style="padding: 0 8px;" href="'. base_url() .'user/user_invoice_payment/' . $value['id'] . '" class="btn btn-warning" title="Payment">Unpaid</a>'; |
|
1280
|
|
|
}else{ |
|
1281
|
|
|
|
|
1282
|
|
|
$payment = ' <button style="padding: 0 8px;" class="btn btn-success" type="button">Paid</button>'; |
|
1283
|
|
|
} $account_arr = $this->db_model->getSelect('first_name,number,last_name','accounts', array('id'=>$value['accountid'])); |
|
1284
|
|
|
$account_array = $account_arr->result_array(); |
|
1285
|
|
|
$date = strtotime($value['invoice_date']); |
|
1286
|
|
|
$date = strtotime("+7 day", $date); |
|
1287
|
|
|
$time = date("Y-m-d h:i:s ",$date); |
|
1288
|
|
|
$json_data['rows'][] = array('cell' => array( |
|
1289
|
|
|
$value['invoice_prefix'].$value['invoiceid'].' ('.$value['type'].')', |
|
1290
|
|
|
$account_array[0]['first_name'].' '.$account_array[0]['last_name'].'</br>'.$account_array[0]['number'], |
|
1291
|
|
|
$invoice_date, |
|
1292
|
|
|
$from_date, |
|
1293
|
|
|
$due_date, |
|
1294
|
|
|
$payment_last, |
|
|
|
|
|
|
1295
|
|
|
$this->common->currency_decimal($value['amount']).' '.$currency_id, |
|
1296
|
|
|
$this->common->currency_decimal($outstanding).' '.$currency_id, |
|
1297
|
|
|
$download.$payment, |
|
1298
|
|
|
|
|
1299
|
|
|
)); |
|
1300
|
|
|
|
|
1301
|
|
|
|
|
1302
|
|
|
} |
|
1303
|
|
|
|
|
1304
|
|
|
$json_data['rows'][] = array('cell' => array( |
|
1305
|
|
|
//$date.'- 0'.$value['id'].'('.$value['type'].')', |
|
|
|
|
|
|
1306
|
|
|
'<b>Grand Total</b>', |
|
1307
|
|
|
'', |
|
1308
|
|
|
'', |
|
1309
|
|
|
'', |
|
1310
|
|
|
'', |
|
1311
|
|
|
'', |
|
1312
|
|
|
"<b>". $grand_total."</b>", |
|
1313
|
|
|
"<b>".$grand_credit."<b>", |
|
|
|
|
|
|
1314
|
|
|
'', |
|
1315
|
|
|
|
|
1316
|
|
|
)); |
|
1317
|
|
|
echo json_encode($json_data); |
|
1318
|
|
|
} |
|
1319
|
|
|
|
|
1320
|
|
View Code Duplication |
function invoice_logo_delete($accountid){ |
|
1321
|
|
|
|
|
1322
|
|
|
$invoiceconf = $this->db_model->getSelect("*", "invoice_conf", array("id"=> $accountid)); |
|
1323
|
|
|
$result=$invoiceconf->result_array(); |
|
1324
|
|
|
$logo=$result[0]['logo']; |
|
1325
|
|
|
$post_arr=array('logo'=>''); |
|
1326
|
|
|
$where_arr=array('logo'=>$logo); |
|
1327
|
|
|
$this->db->where($where_arr); |
|
1328
|
|
|
$this->db->update('invoice_conf',$post_arr); |
|
1329
|
|
|
// redirect(base_url() . 'invoices/invoice_conf/'); |
|
|
|
|
|
|
1330
|
|
|
|
|
1331
|
|
|
} |
|
1332
|
|
|
function invoice_list_view_invoice($invoiceid=false) { |
|
1333
|
|
|
|
|
1334
|
|
|
$data['username'] = $this->session->userdata('user_name'); |
|
|
|
|
|
|
1335
|
|
|
$data['page_title'] = 'Invoice Detail'; |
|
1336
|
|
|
|
|
1337
|
|
|
$cdrs_query = $this->invoices_model->getCdrs_invoice($invoiceid); |
|
1338
|
|
|
|
|
1339
|
|
|
$invoice_cdr_list = array(); |
|
1340
|
|
|
$cdr_list = array(); |
|
1341
|
|
|
if ($cdrs_query->num_rows() > 0) { |
|
1342
|
|
|
foreach ($cdrs_query->result_array() as $cdr) { |
|
1343
|
|
|
$cdr['charge'] = $this->common_model->calculate_currency($cdr['debit'] - $cdr['credit']); |
|
1344
|
|
|
array_push($cdr_list, $cdr); |
|
1345
|
|
|
} |
|
1346
|
|
|
} |
|
1347
|
|
|
$data['invoice_cdr_list'] = $cdr_list; |
|
1348
|
|
|
|
|
1349
|
|
|
$invoice_total_query = $this->Astpp_common->get_invoice_total($invoiceid); |
|
1350
|
|
|
|
|
1351
|
|
|
$total_list = array(); |
|
1352
|
|
|
$invoice_total_list = array(); |
|
1353
|
|
|
|
|
1354
|
|
|
if ($invoice_total_query->num_rows() > 0) { |
|
1355
|
|
|
foreach ($invoice_total_query->result_array() as $total) { |
|
1356
|
|
|
array_push($total_list, $total); |
|
1357
|
|
|
} |
|
1358
|
|
|
} |
|
1359
|
|
|
$data['invoice_total_list'] = $total_list; |
|
1360
|
|
|
$invoicedata = $this->Astpp_common->get_invoice($invoiceid); |
|
1361
|
|
|
$data['invoiceid'] = @$invoicedata[0]['invoiceid']; |
|
1362
|
|
|
$data['invoicedate'] = @$invoicedata[0]['date']; |
|
1363
|
|
|
$data['accountid'] = @$invoicedata[0]['accountid']; |
|
1364
|
|
|
if(!empty($invoicedata)){ |
|
1365
|
|
|
$accountinfo = $this->invoices_model->get_account_including_closed(@$invoicedata[0]['accountid']); |
|
1366
|
|
|
$data['accountinfo'] = $accountinfo; |
|
1367
|
|
|
} |
|
1368
|
|
|
$invoiceconf = $this->invoices_model->get_invoiceconf($accountinfo['reseller']); |
|
|
|
|
|
|
1369
|
|
|
$data['invoiceconf'] = $invoiceconf; |
|
1370
|
|
|
$this->load->view('view_account_invoice_detail', $data); |
|
1371
|
|
|
} |
|
1372
|
|
|
|
|
1373
|
|
|
function invoice_download($invoiceid){ |
|
1374
|
|
|
$this->db->where('id',$invoiceid); |
|
1375
|
|
|
$this->db->select('type'); |
|
1376
|
|
|
$this->db->from('invoices'); |
|
1377
|
|
|
$result=$this->db->get(); |
|
1378
|
|
|
if($result->num_rows() > 0 ){ |
|
1379
|
|
|
$result=$result->result_array(); |
|
1380
|
|
|
$type= $result[0]['type']; |
|
1381
|
|
|
if($type=='I'){ |
|
1382
|
|
|
$this->invoice_main_download($invoiceid); |
|
1383
|
|
|
} |
|
1384
|
|
|
if($type=='R'){ |
|
1385
|
|
|
$this->receipt_download($invoiceid); |
|
1386
|
|
|
} |
|
1387
|
|
|
}else{ |
|
1388
|
|
|
redirect(base_url() . 'invoices/invoice_list/'); |
|
1389
|
|
|
} |
|
1390
|
|
|
} |
|
1391
|
|
|
|
|
1392
|
|
|
function invoice_screen(){ |
|
1393
|
|
|
$login_type = $this->session->userdata['userlevel_logintype']; |
|
1394
|
|
|
if($login_type == -1 || $login_type == 2 ||$login_type == 1 || $login_type == 4){ |
|
1395
|
|
|
if($this->input->post()){ |
|
1396
|
|
|
$data = $this->input->post(); |
|
1397
|
|
View Code Duplication |
if($data['accountid'] == '' || $data['accountid'] == '-Select-' ){ |
|
1398
|
|
|
$this->session->set_flashdata('astpp_notification', 'Please select accounts'); |
|
1399
|
|
|
redirect(base_url()."invoices/invoice_list/"); |
|
1400
|
|
|
} |
|
1401
|
|
|
if(!empty($data)){ |
|
1402
|
|
|
if(isset($data['notes']) && $data['notes'] !=''){ |
|
1403
|
|
|
$this->session->set_userdata('invoice_note',$data['notes']); |
|
1404
|
|
|
} |
|
1405
|
|
|
$date=date('Y-m-d'); |
|
1406
|
|
|
$feture_date=date('Y-m-d', strtotime($date)); |
|
1407
|
|
|
$from_date=$data['fromdate']; |
|
1408
|
|
|
$genrated_date=$data['todate']; |
|
1409
|
|
|
$to_date=date('Y-m-d', strtotime($genrated_date)); |
|
1410
|
|
|
if( $to_date > $feture_date){ |
|
1411
|
|
|
$this->session->set_flashdata('astpp_notification', 'To date should not be greater than current date.'); |
|
1412
|
|
|
redirect(base_url()."invoices/invoice_list/"); |
|
1413
|
|
|
}else{ |
|
1414
|
|
|
$todate=$data['todate'].' '.'23:59:59'; |
|
1415
|
|
|
$from_date=$data['fromdate'].' '.'00:00:01'; |
|
1416
|
|
|
$accountid=$data['accountid']; |
|
1417
|
|
|
$acc_query = $this->db_model->getSelect("*", "accounts", array("id" => $accountid)); |
|
1418
|
|
|
$accountdata = $acc_query->result_array(); |
|
1419
|
|
|
$accountdata=$accountdata[0]; |
|
1420
|
|
|
$screen_path = getcwd()."/cron"; |
|
1421
|
|
|
$screen_filename = "Email_Broadcast_".strtotime('now'); |
|
1422
|
|
|
$command = "cd ".$screen_path." && /usr/bin/screen -d -m -S $screen_filename php cron.php BroadcastEmail"; |
|
1423
|
|
|
exec($command); |
|
1424
|
|
|
$invoice_data_count = 0; |
|
1425
|
|
|
$invoice_conf = array(); |
|
1426
|
|
View Code Duplication |
if($accountdata['reseller_id'] == 0){ |
|
1427
|
|
|
$where = array("accountid"=> 1); |
|
1428
|
|
|
} else{ |
|
1429
|
|
|
$where = array("accountid"=> $accountdata['reseller_id']); |
|
1430
|
|
|
} |
|
1431
|
|
|
$query = $this->db_model->getSelect("*", "invoice_conf", $where); |
|
1432
|
|
View Code Duplication |
if($query->num_rows >0){ |
|
1433
|
|
|
$invoice_conf = $query->result_array(); |
|
1434
|
|
|
$invoice_conf = $invoice_conf[0]; |
|
1435
|
|
|
} else{ |
|
1436
|
|
|
$query = $this->db_model->getSelect("*", "invoice_conf",array("accountid"=> 1)); |
|
1437
|
|
|
$invoice_conf = $query->result_array(); |
|
1438
|
|
|
$invoice_conf = $invoice_conf[0]; |
|
1439
|
|
|
} |
|
1440
|
|
|
$last_invoice_ID = $this->get_invoice_date("invoiceid"); |
|
1441
|
|
View Code Duplication |
if($last_invoice_ID && $last_invoice_ID > 0){ |
|
1442
|
|
|
$last_invoice_ID = ($last_invoice_ID+1); |
|
1443
|
|
|
}else{ |
|
1444
|
|
|
$last_invoice_ID = $invoice_conf['invoice_start_from']; |
|
1445
|
|
|
} |
|
1446
|
|
|
$last_invoice_ID =str_pad($last_invoice_ID,(strlen($last_invoice_ID)+4),'0',STR_PAD_LEFT); |
|
1447
|
|
|
if($accountdata['posttoexternal'] == 1){ |
|
1448
|
|
|
$balance = ($accountdata['credit_limit']-$accountdata['balance']); |
|
1449
|
|
|
}else{ |
|
1450
|
|
|
$balance = $accountdata['balance']; |
|
1451
|
|
|
} |
|
1452
|
|
View Code Duplication |
if($accountdata['invoice_interval'] > 0){ |
|
1453
|
|
|
$due_date = gmdate("Y-m-d H:i:s",strtotime(gmdate("Y-m-d H:i:s")." +".$accountdata['invoice_interval']." days")); |
|
1454
|
|
|
}else{ |
|
1455
|
|
|
$due_date = gmdate("Y-m-d H:i:s",strtotime(gmdate("Y-m-d H:i:s")." +7 days")); |
|
1456
|
|
|
} |
|
1457
|
|
|
$invoice_data = array("accountid"=>$accountdata['id'],"invoice_prefix" =>$invoice_conf['invoice_prefix'],"invoiceid"=>$last_invoice_ID,"reseller_id"=> |
|
1458
|
|
|
$accountdata['reseller_id'],"invoice_date"=>gmdate("Y-m-d H:i:s"),"from_date"=>$from_date,"to_date"=>$todate,"due_date"=>$due_date,"status"=>1,"amount"=>"0.00","balance"=>$balance,'generate_type'=>1,'confirm'=>0,'notes'=>$data['notes']); |
|
1459
|
|
|
// echo "<pre>"; print_r($invoice_data); exit; |
|
|
|
|
|
|
1460
|
|
|
$invoice_note = $this->session->userdata('invoice_note'); |
|
1461
|
|
|
$this->session->unset_userdata('invoice_note'); |
|
1462
|
|
|
$invoice_data['invoice_note']=$invoice_note; |
|
1463
|
|
|
$this->db->insert("invoices",$invoice_data); |
|
1464
|
|
|
$invoiceid = $this->db->insert_id(); |
|
1465
|
|
|
//$generateInvoice->process_invoice($accountdata,$from_date,$todate); |
|
|
|
|
|
|
1466
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'Invoice generation completed .'); |
|
1467
|
|
|
redirect(base_url()."invoices/invoice_manually_edit/".$invoiceid); |
|
1468
|
|
|
|
|
1469
|
|
|
} |
|
1470
|
|
|
} |
|
1471
|
|
|
} else{ |
|
1472
|
|
|
$this->session->set_flashdata('astpp_errormsg', 'No data found.....'); |
|
1473
|
|
|
redirect(base_url()."invoices/invoice_list/"); |
|
1474
|
|
|
} |
|
1475
|
|
|
|
|
1476
|
|
|
} else |
|
1477
|
|
|
{ |
|
1478
|
|
|
$this->session->set_flashdata('astpp_notification', 'Permission Denied.'); |
|
1479
|
|
|
redirect(base_url()."invoices/invoice_list/"); |
|
1480
|
|
|
} |
|
1481
|
|
|
} |
|
1482
|
|
|
|
|
1483
|
|
|
/** |
|
1484
|
|
|
* @param string $select |
|
1485
|
|
|
*/ |
|
1486
|
|
|
function get_invoice_date($select,$accountid=false){ |
|
1487
|
|
|
if($accountid){ |
|
1488
|
|
|
$where = array('type'=>"I","accountid"=>$accountid); |
|
1489
|
|
|
$query = $this->db_model->select($select, "invoices", $where,"to_date","DESC","1","0"); |
|
1490
|
|
|
} else{ |
|
1491
|
|
|
$where = array('type'=>"I"); |
|
1492
|
|
|
$query = $this->db_model->select($select, "invoices", $where,"id","DESC","1","0"); |
|
1493
|
|
|
} |
|
1494
|
|
View Code Duplication |
if($query->num_rows >0){ |
|
1495
|
|
|
$invoiceid = $query->result_array(); |
|
1496
|
|
|
$invoice_date=$invoiceid[0][$select]; |
|
1497
|
|
|
return $invoice_date; |
|
1498
|
|
|
} |
|
1499
|
|
|
return false; |
|
1500
|
|
|
} |
|
1501
|
|
|
function invoice_main_download($invoiceid) { |
|
1502
|
|
|
|
|
1503
|
|
|
$invoicedata = $this->db_model->getSelect("*", "invoices", array("id"=> $invoiceid)); |
|
1504
|
|
|
$invoicedata = $invoicedata->result_array(); |
|
1505
|
|
|
$invoicedata=$invoicedata[0]; |
|
1506
|
|
|
$invoice_path=''; |
|
1507
|
|
|
$accountid = $invoicedata['accountid']; |
|
1508
|
|
|
$acc_file=$invoice_path.$accountid.'/'.$invoiceid; |
|
1509
|
|
|
$accountdata = $this->db_model->getSelect("*","accounts",array("id"=>$accountid)); |
|
1510
|
|
|
$accountdata = $accountdata->result_array(); |
|
1511
|
|
|
$accountdata = $accountdata[0]; |
|
1512
|
|
|
|
|
1513
|
|
|
$login_type = $this->session->userdata['userlevel_logintype']; |
|
1514
|
|
|
$query="select item_type,credit from invoice_details where invoiceid = ".$invoicedata['id']." and item_type='INVPAY' Group By id order by item_type desc"; |
|
1515
|
|
|
// echo $query; exit; |
|
|
|
|
|
|
1516
|
|
|
$invoice_total_query=$this->db->query($query); |
|
1517
|
|
|
if($invoice_total_query->num_rows() > 0){ |
|
1518
|
|
|
$total=$invoice_total_query->result_array(); |
|
1519
|
|
|
foreach($total as $key => $value){ |
|
1520
|
|
|
$debit=$value['credit']; |
|
1521
|
|
|
} |
|
1522
|
|
|
if($debit){ |
|
|
|
|
|
|
1523
|
|
|
// echo 'debit'; exit; |
|
|
|
|
|
|
1524
|
|
|
$invoice_path=$this->config->item('invoices_path'); |
|
1525
|
|
|
$download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; |
|
1526
|
|
|
unlink($download_path); |
|
1527
|
|
|
$res = $this->common->get_invoice_template($invoicedata,$accountdata,"TRUE"); |
|
1528
|
|
|
} |
|
1529
|
|
|
} |
|
1530
|
|
|
$invoice_path=$this->config->item('invoices_path'); |
|
1531
|
|
|
$download_path = $invoice_path.$accountdata["id"].'/'.$invoicedata['invoice_prefix'].$invoicedata['invoiceid']."_invoice.pdf"; |
|
1532
|
|
|
$res = $this->common->get_invoice_template($invoicedata,$accountdata,"TRUE"); |
|
1533
|
|
|
} |
|
1534
|
|
|
function Sec2Minutes( $seconds ) |
|
1535
|
|
|
{ |
|
1536
|
|
|
return sprintf( "%02.2d:%02.2d", floor( $seconds / 60 ), $seconds % 60 ); |
|
1537
|
|
|
} |
|
1538
|
|
|
function receipt_download($invoiceid) { |
|
1539
|
|
|
$login_info = $this->session->userdata('accountinfo'); |
|
1540
|
|
|
ob_start(); |
|
1541
|
|
|
$this->load->library('/html2pdf/html2pdf'); |
|
1542
|
|
|
$template_config=$this->config->item('invoice_template'); |
|
1543
|
|
|
include($template_config.'invoice_template_receipt.php'); |
|
1544
|
|
|
$content = ob_get_clean(); |
|
1545
|
|
|
ob_clean(); |
|
1546
|
|
|
$accountid = $this->common->get_field_name('accountid', 'invoices', $invoiceid); |
|
1547
|
|
|
$accountdata = $this->db_model->getSelect("*","accounts",array("id"=>$accountid)); |
|
1548
|
|
|
$accountdata = $accountdata->result_array(); |
|
1549
|
|
|
$accountdata = $accountdata[0]; |
|
1550
|
|
|
// $accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $accountdata["currency_id"]); |
|
|
|
|
|
|
1551
|
|
|
//$currency = $accountdata["currency_id"]; |
|
|
|
|
|
|
1552
|
|
View Code Duplication |
if($login_info['type'] == -1){ |
|
1553
|
|
|
$data["to_currency"] = Common_model::$global_config['system_config']['base_currency']; |
|
|
|
|
|
|
1554
|
|
|
$currency = $data["to_currency"]; |
|
1555
|
|
|
} elseif($login_info['type'] == 1){ |
|
1556
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $login_info["currency_id"]); |
|
1557
|
|
|
$currency = $accountdata["currency_id"]; |
|
1558
|
|
|
} else{ |
|
1559
|
|
|
$accountdata["currency_id"] = $this->common->get_field_name('currency', 'currency', $login_info["currency_id"]); |
|
1560
|
|
|
$currency = $accountdata["currency_id"]; |
|
1561
|
|
|
} |
|
1562
|
|
|
$invoice_cdr_list = array(); |
|
1563
|
|
|
$invoicedata = $this->db_model->getSelect("*", "invoices", array("id"=> $invoiceid)); |
|
1564
|
|
|
$invoicedata = $invoicedata->result_array(); |
|
1565
|
|
|
$invoicedata=$invoicedata[0]; |
|
1566
|
|
|
|
|
1567
|
|
|
$data['invoiceid'] = @$invoicedata[0]['id']; |
|
|
|
|
|
|
1568
|
|
|
$data['id'] = @$invoicedata['invoiceid']; |
|
1569
|
|
|
|
|
1570
|
|
|
$data['invoice_date'] = @$invoicedata[0]['invoice_date']; |
|
1571
|
|
|
$data['accountid'] = @$invoicedata[0]['accountid']; |
|
1572
|
|
|
$data['from_date'] = @$invoicedata[0]['from_date']; |
|
1573
|
|
|
$data['to_date'] = @$invoicedata[0]['to_date']; |
|
1574
|
|
|
$total_list = array(); |
|
1575
|
|
|
$data['description']=''; |
|
1576
|
|
|
$data['item_type']=''; |
|
1577
|
|
|
$data['debit']=''; |
|
1578
|
|
|
$invoice_total_list = array(); |
|
1579
|
|
|
$query="select item_type,description,created_date,invoiceid,debit,credit from invoice_details where invoiceid = ".$invoiceid." And ( item_type='POSTCHARG' Or item_type='Refill') Group By item_type"; |
|
|
|
|
|
|
1580
|
|
|
$invoice_total_query=$this->db->query($query); |
|
1581
|
|
|
if($invoice_total_query ->num_rows() > 0) { |
|
1582
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
1583
|
|
View Code Duplication |
foreach($invoice_total_query as $key=>$value){ |
|
1584
|
|
|
$data['item_type']=$value['item_type']; |
|
1585
|
|
|
$data['description']=$value['description']; |
|
1586
|
|
|
if($value['item_type'] == 'Refill'){ |
|
1587
|
|
|
$data['debit']=$value['credit']; |
|
1588
|
|
|
}else{ |
|
1589
|
|
|
$data['debit']=$value['debit']; |
|
1590
|
|
|
} |
|
1591
|
|
|
$created_date=$value['created_date']; |
|
1592
|
|
|
$invoicedata['invoiceid']=$value['invoiceid']; |
|
1593
|
|
|
} |
|
1594
|
|
|
}else{ |
|
1595
|
|
|
$query="select item_type,description,created_date,invoiceid,debit,credit from invoice_details where invoiceid = ".$invoiceid." And item_type='SUBCHRG' Group By item_type"; |
|
|
|
|
|
|
1596
|
|
|
$invoice_total_query=$this->db->query($query); |
|
1597
|
|
|
if($invoice_total_query ->num_rows() > 0) { |
|
1598
|
|
|
$invoice_total_query= $invoice_total_query->result_array(); |
|
1599
|
|
View Code Duplication |
foreach($invoice_total_query as $key=>$value){ |
|
1600
|
|
|
$data['item_type']=$value['item_type']; |
|
1601
|
|
|
$data['description']=$value['description']; |
|
1602
|
|
|
if($value['item_type'] == 'Refill'){ |
|
1603
|
|
|
$data['debit']=$value['credit']; |
|
1604
|
|
|
} else{ |
|
1605
|
|
|
$data['debit']=$value['debit']; |
|
1606
|
|
|
} |
|
1607
|
|
|
$created_date=$value['created_date']; |
|
1608
|
|
|
$invoicedata['invoiceid']=$value['invoiceid']; |
|
1609
|
|
|
} |
|
1610
|
|
|
} |
|
1611
|
|
|
} |
|
1612
|
|
|
$data['accountinfo'] = $accountdata; |
|
1613
|
|
|
//Get invoice header information |
|
1614
|
|
|
if($accountdata['reseller_id']=='0') |
|
1615
|
|
|
$accountid = '1'; |
|
1616
|
|
|
else |
|
1617
|
|
|
$accountid = $accountdata['reseller_id']; |
|
1618
|
|
|
$invoiceconf = $this->db_model->getSelect("*", "invoice_conf", array("accountid"=> $accountid)); |
|
1619
|
|
|
$invoiceconf = $invoiceconf->result_array(); |
|
1620
|
|
View Code Duplication |
if(!empty($invoiceconf)){ |
|
1621
|
|
|
$data['invoiceconf'] = $invoiceconf[0]; |
|
1622
|
|
|
}else{ |
|
1623
|
|
|
$invoiceconf = $this->db_model->getSelect("*", "invoice_conf", array("accountid"=> "1")); |
|
1624
|
|
|
$invoiceconf = $invoiceconf->result_array(); |
|
1625
|
|
|
$data['invoiceconf'] = $invoiceconf[0]; |
|
1626
|
|
|
} |
|
1627
|
|
|
|
|
1628
|
|
|
|
|
1629
|
|
|
|
|
1630
|
|
|
// echo '<pre>'; print_r($accountdata); exit; |
|
|
|
|
|
|
1631
|
|
|
//FOR the Customer Address |
|
1632
|
|
|
$customer_address="<div style='font-size:12px;' >"; |
|
1633
|
|
|
if ( $accountdata['company_name'] != "") |
|
1634
|
|
|
$customer_address .= $accountdata['company_name'] . "<br/>"; |
|
1635
|
|
|
if ( $accountdata['address_1'] != "") |
|
1636
|
|
|
$customer_address .= $accountdata['address_1'] . "," .$accountdata['address_2'] .",". "<br/>"; |
|
1637
|
|
|
if ( $accountdata['city'] != "") |
|
1638
|
|
|
$customer_address .= $accountdata['city'] . "<br/>"; |
|
1639
|
|
|
if ( $accountdata['province'] != "") |
|
1640
|
|
|
$customer_address .= $accountdata['province']."<br/>"; |
|
1641
|
|
|
if ( $accountdata['country_id'] != "") |
|
1642
|
|
|
$customer_address .= $this->common->get_field_name('country', 'countrycode', $accountdata['country_id'])."<br/>"; |
|
1643
|
|
|
if ( $accountdata['postal_code'] != "") |
|
1644
|
|
|
$customer_address .= "Pincode - " . $accountdata['postal_code'] . "<br/>"; |
|
1645
|
|
|
else |
|
1646
|
|
|
$customer_address .= "\n"; |
|
1647
|
|
|
// $customer_address .= "Date of Invoice: " .date('d/m/Y', strtotime($invoicedata['invoice_date']))."<br/>"; |
|
|
|
|
|
|
1648
|
|
|
$customer_address .= "</div>"; |
|
1649
|
|
|
|
|
1650
|
|
|
$reseller_id=$accountdata['reseller_id']; |
|
1651
|
|
|
$logo=''; |
|
1652
|
|
|
if(!empty($invoiceconf) && $invoiceconf != ''){ |
|
1653
|
|
|
$logo= $invoiceconf[0]['logo']; |
|
1654
|
|
|
$dir_path= getcwd()."/assets/Logo/"; |
|
1655
|
|
|
// echo $dir_path; exit; |
|
|
|
|
|
|
1656
|
|
|
$path =$dir_path. $logo; |
|
1657
|
|
|
if($logo != ''){ |
|
1658
|
|
|
$src=$path; |
|
1659
|
|
|
$logo = "<img style='height:50px; width:180px; margin-left:70px;' alt='logo' src='".$src."'>"; |
|
1660
|
|
|
}else{ |
|
1661
|
|
|
$path = getcwd()."/assets/images/logo.png"; |
|
1662
|
|
|
$src=$path; |
|
1663
|
|
|
$logo = "<img style='height:50px; width:180px; margin-left:70px;' alt='logo' src='".$src."'>"; |
|
1664
|
|
|
} |
|
1665
|
|
|
} |
|
1666
|
|
|
|
|
1667
|
|
|
|
|
1668
|
|
|
$CALL_DETAILS_TABLE=null; |
|
1669
|
|
|
$CALL_DETAILS_TABLE .= "<tr style='font-family:arial;'>"; |
|
1670
|
|
|
$CALL_DETAILS_TABLE .= "<td style='font-size:12px;padding:7px 5px;width: 35%;text-align:right;border-bottom:1px solid black;border-left:1px solid #000;border-right:1px solid #000;'>".$accountdata['number']."</td>"; |
|
1671
|
|
|
$CALL_DETAILS_TABLE .= "<td style='font-size:12px;padding:7px 5px;width: 25%;border-bottom:1px solid black;text-align:right;border-right:1px solid #000;'>".$invoicedata['invoice_prefix'].$data['id']."</td>"; |
|
1672
|
|
|
$CALL_DETAILS_TABLE .= "<td style='font-size:12px;padding:7px 5px;width: 20%;border-bottom:1px solid black;text-align:right;border-right:1px solid #000;'>".date('Y-m-d', strtotime($invoicedata['from_date']))."</td>"; |
|
1673
|
|
|
$CALL_DETAILS_TABLE .= "<td style='font-size:12px;padding:7px 5px;width: 20%;border-bottom:1px solid black;text-align:right;border-right:1px solid #000;'>".date('Y-m-d', strtotime($invoicedata['from_date']))."</td>"; |
|
1674
|
|
|
$CALL_DETAILS_TABLE .='</tr>'; |
|
1675
|
|
|
|
|
1676
|
|
|
|
|
1677
|
|
|
$RECEIPT_DETAILS_TABLE=null; |
|
1678
|
|
|
$RECEIPT_DETAILS_TABLE .= "<tr style='font-family:arial;'>"; |
|
1679
|
|
|
$RECEIPT_DETAILS_TABLE .= "<td style='font-size:12px;padding:7px 5px;width: 35%;text-align:right;border-bottom:1px solid black;border-left:1px solid #000;border-right:1px solid #000;'>".date('Y-m-d', strtotime($invoicedata['from_date']))."</td>"; |
|
1680
|
|
|
$RECEIPT_DETAILS_TABLE .= "<td style='font-size:12px;padding:7px 5px;width: 25%;border-bottom:1px solid black;text-align:right;border-right:1px solid #000;'>".$data['description']."</td>"; |
|
1681
|
|
|
$RECEIPT_DETAILS_TABLE .= "<td style='font-size:12px;padding:7px 5px;width: 20%;border-bottom:1px solid black;text-align:right;border-right:1px solid #000;'>".$data['item_type']."</td>"; |
|
1682
|
|
|
$RECEIPT_DETAILS_TABLE .= "<td style='font-size:12px;padding:7px 5px;width: 20%;border-bottom:1px solid black;text-align:right;border-right:1px solid #000;'>".$this->common->currency_decimal($this->common_model->calculate_currency($data['debit']))."</td>"; |
|
1683
|
|
|
$RECEIPT_DETAILS_TABLE .='</tr>'; |
|
1684
|
|
|
|
|
1685
|
|
|
|
|
1686
|
|
|
//echo '<pre>'; print_r($data['id']); exit; |
|
|
|
|
|
|
1687
|
|
|
|
|
1688
|
|
|
$MONTHLY_DESC=null; |
|
1689
|
|
|
$MONTHLY_DESC .= "<div style='font-size:12px;' ><b>Account Number :</b> " . $accountdata['number']."<br/>"; |
|
1690
|
|
|
$MONTHLY_DESC .= "<b>Receipt Number :</b> " .$invoicedata['invoice_prefix'].$data['id']."<br/>"; |
|
1691
|
|
|
$MONTHLY_DESC .= "<b>Receipt Date :</b> " .date('Y-m-d', strtotime($invoicedata['from_date']))."<br/></div>"; |
|
1692
|
|
|
|
|
1693
|
|
|
$COMPANY_DETAILS_TABLE = null; |
|
1694
|
|
|
$COMPANY_DETAILS_SET=null; |
|
1695
|
|
|
$COMPANY_DETAILS_SET.= $data['invoiceconf']['company_name']."<br/>"; |
|
1696
|
|
|
$COMPANY_DETAILS_SET.= $data['invoiceconf']['address'].",<br/>"; |
|
1697
|
|
|
$COMPANY_DETAILS_SET.= $data['invoiceconf']['city']; |
|
1698
|
|
|
$COMPANY_DETAILS_SET.= $data['invoiceconf']['zipcode'].",<br/>"; |
|
1699
|
|
|
$COMPANY_DETAILS_SET.= $data['invoiceconf']['province'].",<br/>"; |
|
1700
|
|
|
|
|
1701
|
|
|
$COMPANY_DETAILS_SET.= $data['invoiceconf']['country']."<br/>"; |
|
1702
|
|
|
$COMPANY_DETAILS_SET.= $data['invoiceconf']['telephone']." <br/>"; |
|
1703
|
|
|
$COMPANY_DETAILS_SET.= $data['invoiceconf']['fax']." <br/>"; |
|
1704
|
|
|
$COMPANY_DETAILS_SET.= $data['invoiceconf']['emailaddress']."<br/>"; |
|
1705
|
|
|
$COMPANY_DETAILS_SET.= $data['invoiceconf']['website']."<br/>"; |
|
1706
|
|
|
|
|
1707
|
|
|
if(!empty($data['invoiceconf']) && $data['invoiceconf'] != ''){ |
|
1708
|
|
|
$logo= $data['invoiceconf']['logo']; |
|
1709
|
|
|
|
|
1710
|
|
|
$dir_path= base_url()."upload/"; |
|
1711
|
|
|
// echo $dir_path; exit; |
|
|
|
|
|
|
1712
|
|
|
$path =$dir_path.$data['invoiceconf']['accountid']."_".$data['invoiceconf']['logo']; |
|
1713
|
|
|
if(file_exists($path)){ |
|
1714
|
|
|
if($logo != ''){ |
|
1715
|
|
|
$src=$path; |
|
1716
|
|
|
$logo = "<img style='height:50px; width:180px; margin-left:70px;' alt='logo' src='".$src."'>"; |
|
1717
|
|
|
} else{ |
|
1718
|
|
|
$path = base_url()."/assets/images/logo.png"; |
|
1719
|
|
|
$src=$path; |
|
1720
|
|
|
$logo = "<img style='height:50px; width:180px; margin-left:70px;' alt='logo' src='".$src."'>"; |
|
1721
|
|
|
} |
|
1722
|
|
|
} else{ |
|
1723
|
|
|
$dir_path= base_url()."/upload/logo.png"; |
|
1724
|
|
|
$src=$dir_path; |
|
1725
|
|
|
$logo = "<img style='height:50px; width:180px; margin-left:70px;' alt='logo' src='".$src."'>"; |
|
1726
|
|
|
} |
|
1727
|
|
|
} |
|
1728
|
|
|
$content = str_replace("<CURRENCY>",$currency,$content); |
|
1729
|
|
|
$content = str_replace("<LOGO>",$src,$content); |
|
|
|
|
|
|
1730
|
|
|
$content = str_replace("<MONTHLY_DESC>",$MONTHLY_DESC,$content); |
|
1731
|
|
|
$content = str_replace("<COMPANY_ADD>",$customer_address,$content); |
|
1732
|
|
|
$content = str_replace("<RECEIPT_DETAILS_TABLE>",rtrim($RECEIPT_DETAILS_TABLE,""),$content); |
|
1733
|
|
|
$content = str_replace("<COMPANY_DETAILS_TABLE>",$COMPANY_DETAILS_TABLE,$content); |
|
1734
|
|
|
$content = str_replace("<COMPANY_DETAILS_SET>",$COMPANY_DETAILS_SET,$content); |
|
1735
|
|
|
$content = str_replace("<CALL_DETAILS_TABLE>",$CALL_DETAILS_TABLE,$content); |
|
1736
|
|
|
|
|
1737
|
|
|
|
|
1738
|
|
|
// echo $content ; exit; |
|
|
|
|
|
|
1739
|
|
|
$invoice_path=$this->config->item('invoices_path'); |
|
1740
|
|
|
$download_path = $invoicedata['invoice_prefix'].$data['id'].".pdf"; |
|
1741
|
|
|
$this->html2pdf->pdf->SetDisplayMode('fullpage'); |
|
1742
|
|
|
$this->html2pdf->writeHTML($content); |
|
1743
|
|
|
|
|
1744
|
|
|
$this->html2pdf->Output($download_path,"D"); |
|
1745
|
|
|
|
|
1746
|
|
|
|
|
1747
|
|
|
} |
|
1748
|
|
|
|
|
1749
|
|
|
function calculate_currency($amount,$accountdata){ |
|
1750
|
|
|
$base_currency=Common_model::$global_config['system_config']['base_currency']; |
|
1751
|
|
|
$from_currency=Common_model::$global_config['currency_list'][$base_currency]; |
|
1752
|
|
|
$to_currency = $this->db_model->getSelect("currencyrate", "currency", array("currency"=> $accountdata["currency_id"])); |
|
1753
|
|
|
if($to_currency->num_rows() > 0){ |
|
1754
|
|
|
$to_currency_arr = $to_currency->result_array(); |
|
1755
|
|
|
$to_currency = $to_currency_arr[0]["currencyrate"]; |
|
1756
|
|
|
} |
|
1757
|
|
|
else{ |
|
1758
|
|
|
$to_currency= $from_currency; |
|
1759
|
|
|
} |
|
1760
|
|
|
|
|
1761
|
|
|
$cal_amount = ($amount * $to_currency) / $from_currency; |
|
1762
|
|
|
return $cal_amount; |
|
1763
|
|
|
} |
|
1764
|
|
|
|
|
1765
|
|
|
function format_currency($amount) { |
|
1766
|
|
|
$dp = $this->db_model->getSelect("value", "system", array("name"=> "decimalpoints")); |
|
1767
|
|
|
$dp = $dp->result_array(); |
|
1768
|
|
|
$dp = $dp[0]["value"]; |
|
1769
|
|
|
|
|
1770
|
|
|
return money_format('%.' . $dp . 'n', $amount); |
|
1771
|
|
|
} |
|
1772
|
|
|
|
|
1773
|
|
|
function date_diff_custom($end='2020-06-09 10:30:00', $out_in_array=false){ |
|
1774
|
|
|
$intervalo = date_diff(date_create(), date_create($end)); |
|
1775
|
|
|
$out = $intervalo->format("Years:%Y,Months:%M,Days:%d,Hours:%H,Minutes:%i,Seconds:%s"); |
|
1776
|
|
|
if(!$out_in_array) |
|
1777
|
|
|
return $out; |
|
1778
|
|
|
$a_out = array(); |
|
1779
|
|
|
array_walk(explode(',',$out), |
|
|
|
|
|
|
1780
|
|
|
function($val,$key) use(&$a_out){ |
|
|
|
|
|
|
1781
|
|
|
$v=explode(':',$val); |
|
1782
|
|
|
$a_out[$v[0]] = $v[1]; |
|
1783
|
|
|
}); |
|
1784
|
|
|
return $a_out; |
|
1785
|
|
|
} |
|
1786
|
|
|
function invoice_list_search() { |
|
1787
|
|
|
$ajax_search = $this->input->post('ajax_search', 0); |
|
1788
|
|
|
|
|
1789
|
|
|
if ($this->input->post('advance_search', TRUE) == 1) { |
|
1790
|
|
|
$this->session->set_userdata('advance_search', $this->input->post('advance_search')); |
|
1791
|
|
|
$action = $this->input->post(); |
|
1792
|
|
|
|
|
1793
|
|
|
echo '<pre>'; |
|
1794
|
|
|
print_r($action); |
|
1795
|
|
|
unset($action['action']); |
|
1796
|
|
|
unset($action['advance_search']); |
|
1797
|
|
|
$action['from_date'][0]=$action['from_date'][0] ? $action['from_date'][0]." 00:00:00" :''; |
|
1798
|
|
|
$action['invoice_date'][0]=$action['invoice_date'][0] ? $action['invoice_date'][0]." 00:00:00" : ''; |
|
1799
|
|
|
$this->session->set_userdata('invoice_list_search', $action); |
|
1800
|
|
|
} |
|
1801
|
|
|
if (@$ajax_search != 1) { |
|
1802
|
|
|
redirect(base_url() . 'invoices/invoice_list/'); |
|
1803
|
|
|
} |
|
1804
|
|
|
} |
|
1805
|
|
|
function invoice_list_clearsearchfilter() { |
|
1806
|
|
|
$this->session->set_userdata('advance_search', 0); |
|
1807
|
|
|
$this->session->set_userdata('invoice_list_search', ""); |
|
1808
|
|
|
} |
|
1809
|
|
|
/**============ From below code developed for ASTPP version 2.0 ======================================**/ |
|
1810
|
|
View Code Duplication |
function generate_receipt($accountid,$amount,$accountinfo,$last_invoice_ID,$invoice_prefix,$due_date){ |
|
1811
|
|
|
$invoice_data = array("accountid"=>$accountid,"invoice_prefix" =>$invoice_prefix,"invoiceid"=>'0000'.$last_invoice_ID,"reseller_id"=>$accountinfo['reseller_id'],"invoice_date"=>gmdate("Y-m-d H:i:s"),"from_date"=> gmdate("Y-m-d H:i:s"),"to_date"=>gmdate("Y-m-d H:i:s"),"due_date"=>$due_date,"status"=>1,"balance"=>$accountinfo['balance'],"amount"=>$amount,"type"=>'R',"confirm"=>'1'); |
|
1812
|
|
|
$this->db->insert("invoices",$invoice_data); |
|
1813
|
|
|
$invoiceid = $this->db->insert_id(); |
|
1814
|
|
|
return $invoiceid; |
|
1815
|
|
|
} |
|
1816
|
|
|
function insert_invoice_total_data($invoiceid,$sub_total,$sort_order){ |
|
1817
|
|
|
$invoice_total_arr = array("invoiceid"=>$invoiceid,"sort_order"=>$sort_order, |
|
1818
|
|
|
"value"=>$sub_total, "title"=>"Sub Total","text"=>"Sub Total","class"=>"1"); |
|
1819
|
|
|
$this->db->insert("invoices_total",$invoice_total_arr); |
|
1820
|
|
|
return $sort_order++; |
|
1821
|
|
|
} |
|
1822
|
|
|
|
|
1823
|
|
|
function apply_invoice_taxes($invoiceid,$accountid,$sort_order){ |
|
1824
|
|
|
$tax_priority=""; |
|
1825
|
|
|
$where = array("accountid"=>$accountid); |
|
1826
|
|
|
$accounttax_query = $this->db_model->getSelectWithOrder("*", "taxes_to_accounts", $where,"ASC","taxes_priority"); |
|
1827
|
|
|
if($accounttax_query->num_rows > 0){ |
|
1828
|
|
|
$accounttax_query = $accounttax_query->result_array(); |
|
1829
|
|
|
foreach($accounttax_query as $tax_key => $tax_value){ |
|
1830
|
|
|
$taxes_info=$this->db->get_where('taxes',array('id'=>$tax_value['taxes_id'])); |
|
1831
|
|
|
if($taxes_info->num_rows() > 0 ){ |
|
1832
|
|
|
$tax_value=$taxes_info->result_array(); |
|
1833
|
|
|
$tax_value=$tax_value[0]; |
|
1834
|
|
View Code Duplication |
if($tax_value["taxes_priority"] == ""){ |
|
1835
|
|
|
$tax_priority = $tax_value["taxes_priority"]; |
|
1836
|
|
|
}else if($tax_value["taxes_priority"] > $tax_priority){ |
|
1837
|
|
|
$query = $this->db_model->getSelect("SUM(value) as total", "invoices_total", array("invoiceid"=> $invoiceid)); |
|
1838
|
|
|
$query = $query->result_array(); |
|
1839
|
|
|
$sub_total = $query["0"]["total"]; |
|
1840
|
|
|
} |
|
1841
|
|
|
$tax_total = (($sub_total * ( $tax_value['taxes_rate'] / 100 )) + $tax_value['taxes_amount'] ); |
|
|
|
|
|
|
1842
|
|
|
$tax_array = array("invoiceid"=>$invoiceid,"title"=>"TAX","text"=>$tax_value['taxes_description'], |
|
1843
|
|
|
"value"=>$tax_total,"class"=>"2","sort_order"=>$sort_order); |
|
1844
|
|
|
$this->db->insert("invoices_total",$tax_array); |
|
1845
|
|
|
$sort_order++; |
|
1846
|
|
|
} |
|
1847
|
|
|
} |
|
1848
|
|
|
} |
|
1849
|
|
|
return $sort_order; |
|
1850
|
|
|
} |
|
1851
|
|
|
function set_invoice_total($invoiceid,$sort_order){ |
|
1852
|
|
|
$query = $this->db_model->getSelect("SUM(value) as total", "invoices_total", array("invoiceid"=> $invoiceid)); |
|
1853
|
|
|
$query = $query->result_array(); |
|
1854
|
|
|
$sub_total = $query["0"]["total"]; |
|
1855
|
|
|
|
|
1856
|
|
|
$invoice_total_arr = array("invoiceid"=>$invoiceid,"sort_order"=>$sort_order, |
|
1857
|
|
|
"value"=>$sub_total,"title"=>"Total","text"=>"Total","class"=>"9"); |
|
1858
|
|
|
$this->db->insert("invoices_total",$invoice_total_arr); |
|
1859
|
|
|
return true; |
|
1860
|
|
|
} |
|
1861
|
|
|
function invoice_delete_statically($inv_id){ |
|
1862
|
|
|
$data=array('deleted'=>1); |
|
1863
|
|
|
$this->db->where('id',$inv_id); |
|
1864
|
|
|
$this->db->update("invoices",$data); |
|
1865
|
|
|
$this->session->set_flashdata('astpp_notification', 'Invoices removed successfully'); |
|
1866
|
|
|
redirect(base_url() . 'invoices/invoice_list/'); |
|
1867
|
|
|
} |
|
1868
|
|
|
function invoice_delete_massege(){ |
|
1869
|
|
|
$this->session->set_flashdata('astpp_notification', 'Invoices removed successfully'); |
|
1870
|
|
|
redirect(base_url() . 'invoices/invoice_list/'); |
|
1871
|
|
|
} |
|
1872
|
|
|
} |
|
1873
|
|
|
|
|
1874
|
|
|
?> |
|
|
|
|
|
|
1875
|
|
|
|
|
1876
|
|
|
|
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()method in theSoncalls the wrong method in the parent class.