611 lines
33 KiB
PHP
611 lines
33 KiB
PHP
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
/**
|
|
* Class : Login (LoginController)
|
|
* Login class to control to authenticate user credentials and starts user's session.
|
|
* @author : Kishor Mali
|
|
* @version : 1.1
|
|
* @since : 15 November 2016
|
|
*/
|
|
class Login extends CI_Controller
|
|
{
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('login_model');
|
|
$this->load->model('Zohobook_api_model','Zohobook_model');
|
|
$this->load->helper('zohobooks_fetch_api_helper');
|
|
}
|
|
|
|
/**
|
|
* Index Page for this controller.
|
|
*/
|
|
public function index()
|
|
{
|
|
$this->isLoggedIn();
|
|
}
|
|
|
|
/**
|
|
* This function used to check the user is logged in or not
|
|
*/
|
|
function isLoggedIn()
|
|
{
|
|
$isLoggedIn = $this->session->userdata('isLoggedIn');
|
|
|
|
if(!isset($isLoggedIn) || $isLoggedIn != TRUE)
|
|
{
|
|
// print_r($this->session->all_userdata());
|
|
$this->load->view('login');
|
|
|
|
}
|
|
else
|
|
{
|
|
redirect('/dashboard');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* This function used to logged in user
|
|
*/
|
|
public function loginMe()
|
|
{
|
|
$this->load->library('form_validation');
|
|
|
|
// $this->form_validation->set_rules('email', 'Email', 'required|valid_email|max_length[128]|xss_clean|trim');
|
|
$this->form_validation->set_rules('password', 'Password', 'required|max_length[32]|');
|
|
$designation='';
|
|
$role='';
|
|
|
|
if($this->form_validation->run() == FALSE)
|
|
{
|
|
$this->index();
|
|
}
|
|
else
|
|
{
|
|
$email = $this->input->post('email');
|
|
$password = $this->input->post('password');
|
|
|
|
$result = $this->login_model->loginMe($email, $password);
|
|
|
|
if(count($result) > 0)
|
|
{
|
|
|
|
// $det= $this->login_model->Accessdep($res->EmpID);
|
|
// print_r($det);
|
|
// die();
|
|
|
|
foreach ($result as $res)
|
|
{
|
|
log_message('ERROR','#####loggin_name : ' . $res->FirstName);
|
|
$sessionArray = array('userId'=>$res->userId,
|
|
'role'=>$res->roleId,
|
|
'roleText'=>$res->role,
|
|
'name'=>$res->FirstName,
|
|
//'Designation'=>$res->Designation,
|
|
'DEPCode'=>$res->DEPCode,
|
|
'HeadDept'=>$res->HeadDept,
|
|
'depaccess'=>$this->login_model->Accessdep($res->EmpID),
|
|
'DepartmentName'=>$res->DepartmentName,
|
|
'EmpID' => $res->EmpID,
|
|
'isLoggedIn' => TRUE
|
|
);
|
|
|
|
$this->session->set_userdata($sessionArray);
|
|
|
|
//$role=$res->roleId;
|
|
//$designation=$res->Designation;
|
|
$DEPCode=$res->DEPCode;
|
|
|
|
|
|
|
|
}
|
|
if ($DEPCode == SECURITY)
|
|
{
|
|
redirect('/Addigr');
|
|
}
|
|
else
|
|
{
|
|
redirect('/dashboard');
|
|
}
|
|
}
|
|
else
|
|
{
|
|
$this->session->set_flashdata('error', 'Email or password mismatch');
|
|
redirect('login');
|
|
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* This function used to load forgot password view
|
|
*/
|
|
function forgotPassword()
|
|
{
|
|
$this->load->view('forgotPassword');
|
|
}
|
|
|
|
|
|
/**
|
|
* To reset password of the user (without one time code)
|
|
*/
|
|
function resetPasswordUser(){
|
|
// echo 'hi';
|
|
// die();
|
|
|
|
$mobileno = $this->input->post('phno');
|
|
$emailid = $this->input->post('email');
|
|
$result = $this->login_model->getuserid($mobileno,$emailid);
|
|
|
|
if(!empty($result)){
|
|
|
|
$string = "abcd".rand(100000,999999)."lmnxyz";
|
|
$string_shuffled = str_shuffle($string);
|
|
$passcode = substr($string_shuffled, 1, 6);
|
|
$password = "SIDH@".$passcode;
|
|
|
|
$mobile = "91".$result[0]->ContactNumber;
|
|
//$msg = "Your Password is 'resico1234' sent from Resico Industries ";
|
|
$msg = "Hi " .$result[0]->FirstName. ",
|
|
\n Your password has been resetted sucessfully.
|
|
\n Please login with your new password '".$password."'";
|
|
|
|
$message = urlencode($msg);
|
|
|
|
$ch=curl_init();
|
|
curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=VNBAIT&Message=".$message."&ServiceName=PROMOTIONAL_HIGH");
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
|
$output =curl_exec($ch);
|
|
curl_close($ch);
|
|
|
|
$resetpassword = getHashedPassword($password);
|
|
|
|
$updatepassword = $this->login_model->updatepassword($result[0]->userId,$resetpassword);
|
|
|
|
echo "<script>alert('Password Send successfully, Please check your mobile.');</script>";
|
|
redirect('/loginMe','refresh');
|
|
}
|
|
else{
|
|
echo "<script>alert('".$mobileno." This Mobile Number is not registered with us.');</script>";
|
|
redirect('/loginMe','refresh');
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
* To Get One time code to reset password of the user (ajax call)
|
|
*/
|
|
/** function getOTP()
|
|
* {
|
|
* $id = $this->input->post('id');
|
|
* $result = $this->login_model->temp($id);
|
|
* if(!empty($result)){
|
|
* $string = 'abcdefghijklmnopqrstuvwxyz0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
* $string_shuffled = str_shuffle($string);
|
|
* $password = substr($string_shuffled, 1, 7);
|
|
* $otp = rand(1000, 9999);
|
|
* echo "resico@".rand(1000,9999);die;
|
|
*
|
|
* //print_r($result);die;
|
|
* //$result[0]->ContactNumber;
|
|
*
|
|
* $mobile = "91".$result[0]->ContactNumber;
|
|
* //$msg = "Your Password is 'resico1234' sent from Resico Industries ";
|
|
* $msg = "Hi " .$result[0]->FirstName. ",
|
|
* \n We have generated One Time Code For You. This code used for reset your password
|
|
* \n YOUR CODE IS'".$password."'and'".$otp."'";
|
|
*
|
|
* $message = urlencode($msg);
|
|
* // echo $mobile , $message;
|
|
* $ch=curl_init();
|
|
* curl_setopt($ch,CURLOPT_URL,"https://smsapi.24x7sms.com/api_2.0/SendSMS.aspx?APIKEY=xegCdYUIMf3&MobileNo=".$mobile."&SenderID=VNBAIT&Message=".$message."&ServiceName=PROMOTIONAL_HIGH");
|
|
* curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
|
|
* $output =curl_exec($ch);
|
|
*
|
|
* //return $output;
|
|
* //print_r($output);exit();
|
|
* curl_close($ch);
|
|
* //echo json_encode($result);
|
|
* $updateotp = $this->login_model->temp2($result[0]->userId,$otp);
|
|
* $data = $updateotp[0]->OTP;
|
|
* echo $data;
|
|
* }}
|
|
*/
|
|
|
|
/**
|
|
* After Getting One time code
|
|
* Reset password of the user (with OTP)
|
|
*/
|
|
/** function resetPasswordConfirmUser(){
|
|
*
|
|
* // $this->load->library('form_validation');
|
|
*
|
|
* // $this->form_validation->set_rules('newPassword','New password','required|max_length[20]');
|
|
* // $this->form_validation->set_rules('confirmPassword','Confirm new password','required|matches[newPassword]|max_length[20]');
|
|
*
|
|
* $newPassword = $this->input->post('newPassword');
|
|
* $ConfirmPassword = $this->input->post('confirmPassword');
|
|
*
|
|
* $mobileno = $this->input->post('phno');
|
|
*
|
|
* $da ta = $this->login_model->getuserdtl($mobileno);
|
|
* $userid = $data[0]->userId;
|
|
* $OTP = NULL;
|
|
*
|
|
* $Array = array('password'=>getHashedPassword($newPassword),'OTP'=>$OTP);
|
|
*
|
|
* $result = $this->login_model->resetpassword($Array,$userid);
|
|
*
|
|
* if($result > 0)
|
|
* {
|
|
* echo "<script>alert('You Password Resetted!');</script>"; redirect('login','refresh');
|
|
* }
|
|
* else
|
|
* {
|
|
* echo "<script>alert('Have Not Update Error Msg!');</script>"; redirect('login','refresh');
|
|
* }
|
|
*
|
|
* }
|
|
*/
|
|
|
|
// start zoho API
|
|
|
|
function zohobooks_api_fetch_all(){
|
|
// print_r($_GET);
|
|
// echo isset($_GET['from']) ? $_GET['from'] : 'n';
|
|
// echo isset($_GET['to']) ? $_GET['to'] : 'n';
|
|
// die();
|
|
try{
|
|
// if (isset($_POST['sync']) || $_GET['from'] != null && $_GET['to'] != null)
|
|
// {
|
|
// $ch=curl_init();
|
|
$this->load->helper('zohobooks_fetch_api_helper');
|
|
if(isset($_GET['from']) && $_GET['from'] != null && isset($_GET['to']) && $_GET['to'] != null)
|
|
{
|
|
$date_today = $_GET['to'];
|
|
$date_yesterday = $_GET['from'];
|
|
}
|
|
else
|
|
{
|
|
$date_today = date('Y-m-d');
|
|
$date_yesterday = date('Y-m-d',strtotime('-3 day',strtotime($date_today)));
|
|
}
|
|
// echo $date_today.'--'.$date_yesterday;
|
|
$chk_acc_token_val = $this->Zohobook_model->get_data('zohobook_accesstoken','id' , 1);
|
|
// print_r($chk_acc_token_val);//die();
|
|
$date = new DateTime($chk_acc_token_val[0]['created_at']);
|
|
//print_r($date);
|
|
$date->add(new DateInterval('PT1H'));
|
|
//print_r($date);
|
|
//echo '****************';
|
|
//print_r(date('Y-m-d h:i:s'));
|
|
$token = 0;
|
|
if ($date->format('Y-m-d H:i:s') > date('Y-m-d H:i:s')) { $token = $chk_acc_token_val[0]['token']; }
|
|
else { $token = generateNewToken(); $tokendata['token'] = $token; $this->Zohobook_model->update($tokendata , 1,'zohobook_accesstoken'); }
|
|
// $token = generateNewToken(); $tokendata['token'] = $token;
|
|
//$this->Zohobook_model->update($tokendata , 1,'zohobook_accesstoken');
|
|
$result = getheringInvoiceDetails($date_today , $date_yesterday , $token);
|
|
// echo json_encode($result);die();
|
|
$headers_new = $result['headers_new'];
|
|
$res = json_decode($result['data'],true);
|
|
$inv_array = $res['invoices'];
|
|
// echo json_encode($inv_array);die();
|
|
foreach($inv_array as $inv){
|
|
$invoice_id = $inv['invoice_id'];
|
|
//filter only einvoice status pushed invoices only
|
|
//&& isset($inv['einvoice_details']) && isset($inv['einvoice_details']['status']) && ($inv['einvoice_details']['status'] == 'pushed')
|
|
if($invoice_id !== "" ){
|
|
$organization_id = '655654572';
|
|
$result2=getheringInvoiceSubDetails($invoice_id,$organization_id,$headers_new);
|
|
$resall = json_decode($result2,true);
|
|
$res2[] = $resall['invoice'];
|
|
}
|
|
}
|
|
$insert_count = 0;
|
|
$update_count = 0;
|
|
// echo json_encode($res2);die();
|
|
foreach($res2 as $rs)
|
|
{
|
|
$gst_no = $rs['gst_no'];
|
|
$invoice_number = $rs['invoice_number'];
|
|
$invoice_date = $rs['date'];
|
|
$status = $rs['status'];
|
|
$due_date = $rs['due_date'];
|
|
|
|
$invoice_time=$rs['created_time'];
|
|
$time_array = explode("T", $invoice_time);
|
|
$time_array = explode("+",$time_array[1]);
|
|
$invoice_time = $time_array[0];
|
|
|
|
$sql_invoice_chk = $this->Zohobook_model->ip_invoices($invoice_number , $invoice_date);
|
|
if($sql_invoice_chk <= 0)
|
|
{
|
|
|
|
$gst_sql = $this->Zohobook_model->ip_clients($gst_no);
|
|
if($gst_sql)
|
|
{
|
|
$client_id = $gst_sql[0]['client_id'];
|
|
log_message('error', 'Data fetch success DB : ip_clients , client_id : '.$client_id);
|
|
}
|
|
else
|
|
{
|
|
log_message('error', 'No data => Data fetch failed DB : ip_clients '.$gst_no);
|
|
$gst_no_data['client_tax_code'] = $gst_no;
|
|
$gst_sql = $this->Zohobook_model->insert($gst_no_data,'ip_clients');
|
|
$client_id = $gst_sql[0]['tax_rate_id'];
|
|
log_message('error', 'New Data Created : DB : ip_clients , client_id : '.$client_id);
|
|
}
|
|
|
|
|
|
$characters = '0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ';
|
|
$charactersLength = strlen($characters);
|
|
$randomString = '';
|
|
for ($i = 0; $i < 16; $i++) { $randomString .= $characters[rand(0, $charactersLength - 1)]; }
|
|
$url_key = $randomString;
|
|
|
|
$ip_invoices['user_id'] = 1;
|
|
$ip_invoices['client_id'] = $client_id;
|
|
$ip_invoices['invoice_group_id'] = 6;
|
|
$ip_invoices['invoice_status_id'] = ($status == 'draft' ? 1 : (($status == 'sent' || $status == 'overdue') ? 2 : 5));
|
|
$ip_invoices['invoice_date_created'] = $invoice_date;
|
|
$ip_invoices['invoice_time_created'] = $invoice_time;
|
|
$ip_invoices['invoice_date_due'] = $due_date;
|
|
$ip_invoices['invoice_number'] = $invoice_number;
|
|
$ip_invoices['invoice_url_key'] = $url_key;
|
|
$ip_invoices['receivedstatus'] = 'ST066';
|
|
$ip_invoices['credit_status'] = 0;
|
|
$invoice_insert_id = $this->Zohobook_model->insert($ip_invoices,'ip_invoices');
|
|
if($invoice_insert_id)
|
|
{
|
|
log_message('error', 'Data insert success DB : ip_invoices client id :'. $client_id);
|
|
$insert_count = $insert_count + 1;
|
|
//start invoice level custom fields
|
|
|
|
//custom fields insert
|
|
|
|
$batch_no = isset($rs['custom_fields'][5]['value']) ? $rs['custom_fields'][5]['value'] : "";
|
|
// $batch_no = "";
|
|
$vehicle_number = $rs['custom_field_hash']['cf_vehicle_number'];
|
|
$transport_mode =$rs['custom_field_hash']['cf_transport_mode'];
|
|
$purchase_order_date = $rs['custom_field_hash']['cf_purchase_order_date'];
|
|
$driver = $rs['custom_field_hash']['cf_driver'];
|
|
$place_of_supply = $rs['custom_field_hash']['cf_place_of_supply'];
|
|
// batch_no
|
|
$ip_invoice_custom_b['invoice_id'] = $invoice_insert_id;
|
|
$ip_invoice_custom_b['invoice_custom_fieldid'] = 62;
|
|
$ip_invoice_custom_b['invoice_custom_fieldvalue'] = $batch_no;
|
|
$result_invoice_custom_insert = $this->Zohobook_model->insert($ip_invoice_custom_b,'ip_invoice_custom');
|
|
if($result_invoice_custom_insert)
|
|
log_message('error', 'Data insert success DB : ip_invoice_custom ');
|
|
else
|
|
log_message('error', 'Data insert failed DB : ip_invoice_custom ');
|
|
// vehicle_number
|
|
$ip_invoice_custom_v['invoice_id'] = $invoice_insert_id;
|
|
$ip_invoice_custom_v['invoice_custom_fieldid'] = 8;
|
|
$ip_invoice_custom_v['invoice_custom_fieldvalue'] = $vehicle_number;
|
|
$res_vehicle = $this->Zohobook_model->insert($ip_invoice_custom_v,'ip_invoice_custom');
|
|
if($res_vehicle)
|
|
log_message('error', 'Data insert success DB : ip_invoice_custom ');
|
|
else
|
|
log_message('error', 'Data insert failed DB : ip_invoice_custom ');
|
|
// transport_mode
|
|
$ip_invoice_custom_t['invoice_id'] = $invoice_insert_id;
|
|
$ip_invoice_custom_t['invoice_custom_fieldid'] = 7;
|
|
$ip_invoice_custom_t['invoice_custom_fieldvalue'] = $transport_mode;
|
|
$res_transport_mode = $this->Zohobook_model->insert($ip_invoice_custom_t,'ip_invoice_custom');
|
|
if($res_transport_mode)
|
|
log_message('error', 'Data insert success DB : ip_invoice_custom ');
|
|
else
|
|
log_message('error', 'Data insert failed DB : ip_invoice_custom ');
|
|
// purchase_order_date
|
|
$ip_invoice_custom_p['invoice_id'] = $invoice_insert_id;
|
|
$ip_invoice_custom_p['invoice_custom_fieldid'] = 15;
|
|
$ip_invoice_custom_p['invoice_custom_fieldvalue'] = $purchase_order_date;
|
|
$res_purchase_order_date =$this->Zohobook_model->insert($ip_invoice_custom_p,'ip_invoice_custom');
|
|
if($res_purchase_order_date)
|
|
log_message('error', 'Data insert success DB : ip_invoice_custom ');
|
|
else
|
|
log_message('error', 'Data insert failed DB : ip_invoice_custom ');
|
|
// driver
|
|
$ip_invoice_custom_d['invoice_id'] = $invoice_insert_id;
|
|
$ip_invoice_custom_d['invoice_custom_fieldid'] = 58;
|
|
$ip_invoice_custom_d['invoice_custom_fieldvalue'] = $driver;
|
|
$res_driver = $this->Zohobook_model->insert($ip_invoice_custom_d,'ip_invoice_custom');
|
|
if($res_driver)
|
|
log_message('error', 'Data insert success DB : ip_invoice_custom ');
|
|
else
|
|
log_message('error', 'Data insert failed DB : ip_invoice_custom ');
|
|
// place_of_supply
|
|
$ip_invoice_custom_d['invoice_id'] = $invoice_insert_id;
|
|
$ip_invoice_custom_d['invoice_custom_fieldid'] = 10;
|
|
$ip_invoice_custom_d['invoice_custom_fieldvalue'] = $place_of_supply;
|
|
$res_place = $this->Zohobook_model->insert($ip_invoice_custom_d,'ip_invoice_custom');
|
|
if($res_place)
|
|
log_message('error', 'Data insert success DB : ip_invoice_custom ');
|
|
else
|
|
log_message('error', 'Data insert failed DB : ip_invoice_custom ');
|
|
//end invoice level custom fields
|
|
|
|
//if line items available
|
|
if(isset($rs['line_items']) && count($rs['line_items']) > 0)
|
|
{
|
|
log_message('error', 'Processing line items'.count($rs['line_items']));
|
|
|
|
for($i = 0; $i< count($rs['line_items']);$i++)
|
|
{ //start insert line items
|
|
$sku = $rs['line_items'][$i]['sku'];
|
|
|
|
|
|
$item_price = $rs['line_items'][$i]['rate'];
|
|
$item_order = $rs['line_items'][$i]['item_order'];
|
|
$item_product_unit = $rs['line_items'][$i]['unit'];
|
|
$item_name = $rs['line_items'][$i]['name'];
|
|
$item_description = $rs['line_items'][$i]['description'];
|
|
$item_quantity = $rs['line_items'][$i]['quantity'];
|
|
$cgst = $rs['line_items'][$i]['line_item_taxes'][1]['tax_name'];
|
|
$sgst = $rs['line_items'][$i]['line_item_taxes'][0]['tax_name'];
|
|
$cgst = $cgst[4];
|
|
$sgst = $sgst[4];
|
|
$cgst = $cgst.'.000';
|
|
$getcgsttax = $this->Zohobook_model->ip_tax_rates($cgst);
|
|
if($getcgsttax)
|
|
{
|
|
$cgsttaxid = $getcgsttax[0]['tax_rate_id'];
|
|
log_message('error', 'Data fetch success DB : ip_tax_rates cgst'. $cgst);
|
|
}
|
|
else
|
|
{
|
|
log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $cgst);
|
|
$cgst_data['tax_rate_percent'] = $cgst;
|
|
$getcgsttax = $this->Zohobook_model->insert($cgst_data,'ip_tax_rates');
|
|
$cgsttaxid = $getcgsttax[0]['tax_rate_id'];
|
|
log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$cgsttaxid);
|
|
}
|
|
|
|
$sgst = $sgst.'.000';
|
|
$getsgsttax = $this->Zohobook_model->ip_tax_rates($sgst);
|
|
if($getsgsttax)
|
|
{
|
|
$sgsttaxid = $getsgsttax[0]['tax_rate_id'];
|
|
log_message('error', 'Data fetch success DB : ip_tax_rates sgst'. $sgst);
|
|
}
|
|
else
|
|
{
|
|
log_message('error', 'No data => Data fetch failed DB : ip_tax_rates '. $sgst);
|
|
$sgst_data['tax_rate_percent'] = $sgst;
|
|
$getsgsttax = $this->Zohobook_model->insert($sgst_data,'ip_tax_rates');
|
|
$sgsttaxid = $getsgsttax[0]['tax_rate_id'];
|
|
log_message('error', 'New Data Created : DB : ip_tax_rates , tax_rate_id : '.$sgsttaxid);
|
|
}
|
|
|
|
$item_subtotal = $rs['line_items'][$i]['item_total'];
|
|
|
|
|
|
$item_sgst_amt = $rs['line_items'][$i]['line_item_taxes'][0]['tax_amount'];
|
|
$item_cgst_amt = $rs['line_items'][$i]['line_item_taxes'][1]['tax_amount'];
|
|
$item_tax_total = ($item_sgst_amt + $item_cgst_amt);
|
|
$item_total = ($item_subtotal + $item_tax_total);
|
|
|
|
$item_discount = 0.00;
|
|
$item_igst_amt = 0.00;
|
|
// if($batch_no==""){ $batch_no = "";}
|
|
|
|
|
|
$sku_sql = $this->Zohobook_model->ip_products($sku);
|
|
if($sku_sql)
|
|
{
|
|
$product_id = $sku_sql[0]['product_id'];
|
|
log_message('error', 'Data fetch success DB : ip_products , product_id : '.$product_id);
|
|
}
|
|
else
|
|
{
|
|
log_message('error', 'No data => Data fetch failed DB : ip_products '. $sku);
|
|
$sku_data['product_name'] = $item_name;
|
|
$sku_data['product_description'] = $item_description;
|
|
$sku_data['sku'] = $sku;
|
|
$sku_sql = $this->Zohobook_model->insert($sku_data,'ip_products');
|
|
$product_id = $sku_sql[0]['sku'];
|
|
log_message('error', 'sku'.$sku);
|
|
log_message('error', 'New Data Created : DB : product_id , product_id : '.$product_id);
|
|
}
|
|
|
|
//#1
|
|
|
|
$ip_invoice_items['invoice_id'] = $invoice_insert_id;
|
|
$ip_invoice_items['item_product_id'] = $product_id;
|
|
$ip_invoice_items['item_date_added'] = $invoice_date;
|
|
$ip_invoice_items['item_name'] = $item_name;
|
|
$ip_invoice_items['item_description'] = $item_description;
|
|
$ip_invoice_items['item_quantity'] = $item_quantity;
|
|
$ip_invoice_items['item_price'] = $item_price;
|
|
$ip_invoice_items['item_order'] = $item_order;
|
|
$ip_invoice_items['item_product_unit'] = $item_product_unit;
|
|
$ip_invoice_items['Sgst_item_tax_rate_id'] = $sgsttaxid;
|
|
$ip_invoice_items['Cgst_item_tax_rate_id'] = $cgsttaxid;
|
|
$item_insert_id = $this->Zohobook_model->insert($ip_invoice_items,'ip_invoice_items');
|
|
if($item_insert_id)
|
|
log_message('error', 'Data insert success DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid);
|
|
else
|
|
log_message('error', 'Data insert failed DB : ip_invoice_items => Sgst_item_tax_rate_id :'. $sgsttaxid);
|
|
|
|
//tax amount -- ip_invoice_item_amounts - table
|
|
$ip_invoice_item_amounts['item_id'] = $item_insert_id;
|
|
$ip_invoice_item_amounts['item_subtotal'] = $item_subtotal;
|
|
$ip_invoice_item_amounts['item_tax_total'] = $item_tax_total;
|
|
$ip_invoice_item_amounts['item_total'] = $item_total;
|
|
$ip_invoice_item_amounts['item_sgst_amt'] = $item_sgst_amt;
|
|
$ip_invoice_item_amounts['item_cgst_amt'] = $item_cgst_amt;
|
|
$ip_invoice_item_amounts['item_discount'] = $item_discount;
|
|
$ip_invoice_item_amounts['item_igst_amt'] = $item_igst_amt;
|
|
$result_tax_amount_insert = $this->Zohobook_model->insert($ip_invoice_item_amounts,'ip_invoice_item_amounts');
|
|
if($result_tax_amount_insert)
|
|
log_message('error', 'Data insert success DB : ip_invoice_item_amounts ');
|
|
else
|
|
log_message('error', 'Data insert failed DB : ip_invoice_item_amounts ');
|
|
|
|
} //end line items insert
|
|
|
|
}
|
|
else
|
|
{
|
|
log_message('error', 'Line Items not found in API result');
|
|
}
|
|
}
|
|
else
|
|
{
|
|
log_message('error', 'Data insert failed DB : ip_invoice_items client id :'. $client_id);
|
|
}
|
|
|
|
|
|
}
|
|
else // update invoice status, especially for cancelled invoices
|
|
{
|
|
if($status == "void" || $status == "sent" || $status == "ovedue")
|
|
{
|
|
$sql_invoice_update = array();
|
|
$sql_invoice_update['invoice_status_id'] = (($status == "sent" || $status == "ovedue") ? 2 : 5);
|
|
// echo 'script' . $invoice_number. $status;
|
|
// print_r( $sql_invoice_update);
|
|
// echo '<br>';
|
|
$sql_invoice_update = $this->Zohobook_model->sql_invoice_update($sql_invoice_update,$invoice_number,$invoice_date,'ip_invoices');
|
|
if($sql_invoice_update)
|
|
{
|
|
log_message('error', 'Data update success DB : ip_invoices ');
|
|
}
|
|
else
|
|
{
|
|
log_message('error', 'Data update failed DB : ip_invoices ');
|
|
}
|
|
$update_count = $update_count + 1;
|
|
}
|
|
}
|
|
}
|
|
echo 'new invoice inserted count- '. $insert_count . '/'.'status updated count - ' . $update_count;
|
|
|
|
// curl_close($ch);
|
|
// }
|
|
}
|
|
catch (Exception $e) {
|
|
$data['err'] = $e->getMessage();
|
|
$data['last_query'] = $this->db->last_query();
|
|
$this->Zohobook_model->insert($data,'zohobook_api_err');
|
|
log_message('ERROR', "Data insertion failed : " . $e->getMessage());
|
|
|
|
}
|
|
}
|
|
//end
|
|
// END zoho API
|
|
|
|
function check_existing_invoice_with_item($arrToCheck,$arrOfInvoices)
|
|
{
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|