842 lines
30 KiB
PHP
842 lines
30 KiB
PHP
<?php if(!defined('BASEPATH')) exit('No direct script access allowed');
|
|
|
|
require APPPATH . '/libraries/BaseController.php';
|
|
require APPPATH . '/third_party/mpdf/mpdf.php';
|
|
|
|
/**
|
|
* Class : purchaseorder (PurchaseorderController)
|
|
* User Class to control all user related operations.
|
|
* @author : VenbaMail Mali
|
|
* @version : 1.1
|
|
* @since : 15 Feb 2016
|
|
*/
|
|
class quality extends BaseController
|
|
{
|
|
/**
|
|
* This is default constructor of the class
|
|
*/
|
|
public function __construct()
|
|
{
|
|
parent::__construct();
|
|
$this->load->model('quality_model');
|
|
$this->load->library('form_validation');
|
|
$this->load->model('Zohobook_api_model','Zohobook_model');
|
|
$this->load->helper('zohobooks_fetch_api_helper');
|
|
//$this->load->library('dompdf_gen');
|
|
$this->isLoggedIn();
|
|
}
|
|
/**
|
|
* This function used to load the first screen of the user
|
|
*/
|
|
public function index()
|
|
{
|
|
$data['products'] = $this->quality_model->getAllprodcuts();
|
|
$data['customers'] = $this->quality_model->getAllcustomers();
|
|
$data['existspec'] = $this->quality_model->getAllspec();
|
|
$data['existspecinward'] = $this->quality_model->getAllspecInward();
|
|
$this->global['pageTitle'] = 'Siddharth : Quality Master';
|
|
|
|
$this->loadViews("qualitymasterlistview", $this->global, $data , NULL);
|
|
}
|
|
|
|
|
|
public function reportList()
|
|
{
|
|
$data['records'] = $this->quality_model->getTestMasterforList();
|
|
|
|
$this->global['pageTitle'] = 'Siddharth : Prodcut Report List ';
|
|
$this->loadViews("reportmasterlist", $this->global, $data , NULL);
|
|
}
|
|
|
|
public function reportListInward()
|
|
{
|
|
$data['records'] = $this->quality_model->getTestMasterforListInward();
|
|
|
|
$this->global['pageTitle'] = 'Siddharth : Report List Inward';
|
|
$this->loadViews("reportmasterlist_inward", $this->global, $data , NULL);
|
|
}
|
|
|
|
|
|
|
|
function addNewPage()
|
|
{
|
|
$data['productsoutward'] = $this->quality_model->getAllprodcuts();
|
|
$data['customersoutward'] = $this->quality_model->getAllcustomers();
|
|
|
|
$data['productsinward'] = $this->quality_model->getAllprodcutsInward();
|
|
$data['customersinward'] = $this->quality_model->getAllcustomersInward();
|
|
|
|
$this->global['pageTitle'] = 'Siddharth : Quality Master';
|
|
|
|
$this->loadViews("qualitymaster", $this->global, $data , NULL);
|
|
}
|
|
|
|
function saveSpectficationData()
|
|
{
|
|
$product = $this->input->post('param2');
|
|
$customer = $this->input->post('param3');
|
|
$jsondata = $this->input->post('param1');
|
|
$type = $this->input->post('param4');
|
|
|
|
|
|
//echo $type;die();
|
|
$createdby = $this->session->userdata ( 'userId' );
|
|
$phpdata = json_decode($jsondata,true);
|
|
$total = 0;
|
|
// echo $product .'-'. $customer;
|
|
//print_r($phpdata);die();
|
|
|
|
foreach($phpdata as $data)
|
|
{
|
|
$name = $data['Name'];
|
|
$name = strtoupper($name);
|
|
$uom = $data['UOM'];
|
|
$min = $data['Min'];
|
|
$max = $data['Max'];
|
|
$temp = $data['Temp'];
|
|
$rawsandtest = $data['Raw Sand Test'];
|
|
|
|
$res = 0;
|
|
if(strtolower($rawsandtest) == 'yes')
|
|
{
|
|
$rawsandtest = 1;
|
|
}
|
|
else
|
|
{
|
|
$rawsandtest = 0;
|
|
}
|
|
|
|
|
|
|
|
$isExist = $this->quality_model->checkExist($product,$customer,$name,$type);
|
|
//echo $isExist[0]->count;die();
|
|
if($isExist[0]->count == 0)
|
|
{
|
|
|
|
$tostore = array('customer_id'=>$customer,'product_id'=>$product,'testtype'=>$name,'uom'=>$uom,'min'=>$min,'max'=>$max,'temp'=>$temp,'type'=>$type,'subtype' => $rawsandtest,'created_by'=>$createdby);
|
|
//print_r($tostore);
|
|
$res = $this->quality_model->addSpecMast($tostore);
|
|
//echo 'i'.$res;
|
|
}
|
|
else if($isExist[0]->count == 1)
|
|
{
|
|
|
|
$tostore = array('uom'=>$uom,'min'=>$min,'max'=>$max,'temp'=>$temp,'type'=>$type,'subtype' => $rawsandtest,'updated_by'=>$createdby);
|
|
$res = $this->quality_model->updateSpecMast($tostore,$product,$customer,$name,$type);
|
|
//echo 'u'.$res;
|
|
}
|
|
|
|
$total +=$res;
|
|
}
|
|
|
|
echo $total.'- Specification Saved Successfully';
|
|
}
|
|
|
|
function deleteSpecification()
|
|
{
|
|
$spname = $this->input->post('param1');
|
|
$product = $this->input->post('param2');
|
|
$customer = $this->input->post('param3');
|
|
$type = $this->input->post('param4');
|
|
|
|
$res = $this->quality_model->deleteSpecification($spname,$product,$customer,$type);
|
|
if($res == 1)
|
|
{
|
|
echo "Deleted Successfully..!";
|
|
}
|
|
else
|
|
{
|
|
echo "Something Went Wrong..!Try later";
|
|
}
|
|
|
|
}
|
|
|
|
function report()
|
|
{
|
|
|
|
$data['records'] = $this->quality_model->getDataforReport();
|
|
$data['emplist'] = $this->quality_model->getEmplistforReport();
|
|
$this->global['pageTitle'] = 'Siddharth : Inspection Report Screen';
|
|
$this->loadViews("qualityreport", $this->global, $data, NULL);
|
|
}
|
|
|
|
function viewSpec()
|
|
{
|
|
$prodcutid = $this->uri->segment(3);
|
|
$customerid =$this->uri->segment(4);
|
|
$type =$this->uri->segment(5);
|
|
$data['specifications'] = $this->quality_model->getIndividualSpec($prodcutid,$customerid,$type);
|
|
$this->global['pageTitle'] = 'Siddharth : View reports Lists';
|
|
|
|
$this->loadViews("viewIndSpec", $this->global, $data, NULL);
|
|
|
|
}
|
|
|
|
function viewIndReport()
|
|
{
|
|
$reportid = $this->uri->segment(3);
|
|
|
|
$data['reportdata'] = $this->quality_model->getIndividualReportData($reportid);
|
|
$this->global['pageTitle'] = 'Siddharth : View Individual Report';
|
|
$this->loadViews("viewindreport", $this->global, $data, NULL);
|
|
|
|
}
|
|
|
|
function viewIndInwardReport()
|
|
{
|
|
$reportid = $this->uri->segment(3);
|
|
|
|
$data['reportdata'] = $this->quality_model->getIndividualInwardReportData($reportid);
|
|
$this->global['pageTitle'] = 'Siddharth : View Individual Report';
|
|
$this->loadViews("viewindInwardreport", $this->global, $data, NULL);
|
|
|
|
}
|
|
|
|
function printReportPDF()
|
|
{
|
|
$type = '';
|
|
$html = '';
|
|
$filename = '';
|
|
if($this->input->post('type'))
|
|
{
|
|
$type = $this->input->post('type');
|
|
}
|
|
$reportid = $this->input->post('rid');
|
|
|
|
if($type != 'INWARD' or $type == ''){
|
|
$data['reportdata'] = $this->quality_model->getIndividualReportData($reportid);
|
|
$filename = 'PRE DESPATCH INSPECTION REPORT'.$reportid;
|
|
$html = $this->load->View("viewindreportpdf",$data,true);
|
|
}
|
|
else if($type == 'INWARD')
|
|
{
|
|
$data['reportdata'] = $this->quality_model->getIndividualInwardReportData($reportid);
|
|
$filename = 'INWARD MATERIAL INSPECTION REPORT'.$reportid;
|
|
$html = $this->load->View("viewindinwardreportpdf",$data,true);
|
|
}
|
|
// echo $html;die;
|
|
ob_end_clean();
|
|
$mpdf=new mPDF('utf-8','A4-P',7,10,10, 10, 10, 24, 4, 6);
|
|
$mpdf->SetDisplayMode('fullpage');
|
|
$mpdf->showImageErrors = true;
|
|
$mpdf->list_indent_first_level = 1;
|
|
$mpdf->setAutoTopMargin = 'stretch';
|
|
$mpdf->setAutoBottomMargin = 'stretch';
|
|
$mpdf->WriteHTML($html);
|
|
$mpdf->Output($filename.'.pdf','I');
|
|
|
|
}
|
|
|
|
function getAllSpecforReport()
|
|
{
|
|
$productid = $this->input->post('param1');
|
|
$customerid = $this->input->post('param2');
|
|
$res = '';
|
|
if($this->input->post('param3'))
|
|
{
|
|
$ttype = $this->input->post('param3');
|
|
$res = $this->quality_model->getSpecifications($productid,$customerid,$ttype);
|
|
}
|
|
else
|
|
{
|
|
|
|
$res = $this->quality_model->getSpecifications($productid,$customerid);
|
|
}
|
|
|
|
|
|
echo json_encode($res);
|
|
}
|
|
|
|
|
|
function saveTestReportData()
|
|
{
|
|
|
|
|
|
date_default_timezone_get('Asia/Kolkata');
|
|
$testjson = $this->input->post('param1');
|
|
$loijson = $this->input->post('param2');
|
|
$afsjson = $this->input->post('param3');
|
|
$invoiceno = $this->input->post('param4');
|
|
$batchno = $this->input->post('param5');
|
|
$chart = $this->input->post('param7');
|
|
$batchno = date_format(date_create($batchno),'Y-m-d');
|
|
|
|
$approver = $this->input->post('param6');
|
|
|
|
$testphpdata = json_decode($testjson,true);
|
|
$loiphpdata = json_decode($loijson,true);
|
|
|
|
$afsphpdata = json_decode($afsjson,true);
|
|
//print_r($afsphpdata);die();
|
|
$createdon = date('Y-m-d H:i:s');
|
|
$createby = $this->session->userdata ( 'userId' );
|
|
$document = null;
|
|
if(!empty($_FILES['rfile']['name']))
|
|
{
|
|
|
|
|
|
$fs = $this->uploadFile();
|
|
$document = $fs;
|
|
|
|
}
|
|
|
|
$masterreportdata = array('invoiceid'=>$invoiceno,'batchdate'=>$batchno,'createdby'=>$createby,'createdon'=>$createdon,'approvedby'=>$approver,'chartdata'=>$chart,'document'=>$document);
|
|
$MASTERID = $this->quality_model->saveMasterTestData($masterreportdata);
|
|
|
|
|
|
|
|
$descrition = '';
|
|
$min = '';
|
|
$max = '';
|
|
$uom = '';
|
|
$act1 = '';
|
|
$act2 = '';
|
|
$act3 = '';
|
|
$average = '';
|
|
$results = '';
|
|
$remarks1 = '';
|
|
foreach($testphpdata as $data)
|
|
{
|
|
//print_r($data);die();
|
|
$descrition = $data['Description'];
|
|
$min = $data['SpecificationMin'];
|
|
$max = $data['SpecificationMax'];
|
|
$uom = $data['SpecificationUOM'];
|
|
$act1 = $data['ACT X1'];
|
|
$act2 = $data['ACT X2'];
|
|
$act3 = $data['ACT X3'];
|
|
$average = $data['Average'];
|
|
$results = $data['Results'];
|
|
$remarks1 = $data['Remarks'];
|
|
$testreportdata = array('testreport_id'=>$MASTERID,'description'=>$descrition,'min'=>$min,'max'=>$max,'UOM'=>$uom,'act1'=>$act1,'act2'=>$act2,'act3'=>$act3,'average'=>$average,'result'=>$results,'remarks'=>$remarks1);
|
|
$reportid = $this->quality_model->saveTestReportData($testreportdata);
|
|
}
|
|
|
|
|
|
$start = '';
|
|
$end = '';
|
|
$temp = '';
|
|
$w1 = '';
|
|
$w2 = '';
|
|
$w3 = '';
|
|
$loip = '';
|
|
$remark = '';
|
|
foreach($loiphpdata as $loi)
|
|
{
|
|
$start = $loi['Heating Timestart'];
|
|
$end = $loi['Heating Timeend'];
|
|
$temp = $loi['Temp *c'];
|
|
$w1 = $loi['Crucible Weight w1(g)'];
|
|
$w2 = $loi['Before Heatingw2(g)'];
|
|
$w3 = $loi['After Heatingw3(g)'];
|
|
$loip = $loi['L.O.I %'];
|
|
$remark = $loi['Remarks'];
|
|
//echo $loip;
|
|
//echo $remark;die();
|
|
$loitabledata = array('testreport_id'=>$MASTERID,'start_time'=>$start,'end_time'=>$end,'temp'=>$temp,'w1'=>$w1,'w2'=>$w2,'w3'=>$w3,'loi_percentage'=>$loip,'remarks'=>$remark);
|
|
$loiid = $this->quality_model->saveTestReportLOIData($loitabledata);
|
|
|
|
}
|
|
|
|
$count =0;
|
|
foreach($afsphpdata as $afs)
|
|
{
|
|
$count++;
|
|
if($count != 12){
|
|
$ssize = $afs['Sieve Size µm'];
|
|
$sandweight = $afs['Sand Weight'];
|
|
$Percentage = $afs['Percentage'];
|
|
$Multiplier = $afs['Multiplier'];
|
|
$Product = $afs['Product'];
|
|
$afstabledata = array('testreport_id'=>$MASTERID,'sieve_size'=>$ssize,'sandweight'=>$sandweight,'percentage'=>$Percentage,'multiplier'=>$Multiplier,'product'=>$Product);
|
|
$afsid = $this->quality_model->saveTestReportAFSData($afstabledata);
|
|
}
|
|
}
|
|
|
|
echo "Report Data Saved Successfully!";
|
|
|
|
|
|
}
|
|
|
|
|
|
function saveInwardTestReportData()
|
|
{
|
|
|
|
|
|
|
|
date_default_timezone_get('Asia/Kolkata');
|
|
$testjson = $this->input->post('param1');
|
|
$loijson = $this->input->post('param2');
|
|
$afsjson = $this->input->post('param3');
|
|
|
|
$igrno = $this->input->post('param4');
|
|
$igrlineitemno = $this->input->post('param5');
|
|
$chart = $this->input->post('param7');
|
|
$report_date = $this->input->post('param8');
|
|
$report_date = date_format(date_create($report_date),'Y-m-d');
|
|
|
|
$approver = $this->input->post('param6');
|
|
|
|
$testphpdata = json_decode($testjson,true);
|
|
$loiphpdata = json_decode($loijson,true);
|
|
|
|
$afsphpdata = json_decode($afsjson,true);
|
|
//print_r($afsphpdata);die();
|
|
$createdon = date('Y-m-d H:i:s');
|
|
$createby = $this->session->userdata ( 'userId' );
|
|
$document = null;
|
|
if(!empty($_FILES['rfile']['name']))
|
|
{
|
|
|
|
|
|
$fs = $this->uploadFile();
|
|
$document = $fs;
|
|
|
|
}
|
|
$masterreportdata = array('igrno'=>$igrno,'igrlineitemno'=>$igrlineitemno,'batchdate'=>$report_date,'createdby'=>$createby,'createdon'=>$createdon,'approvedby'=>$approver,'chartdata'=>$chart,'document'=>$document);
|
|
//print_r($masterreportdata);die;
|
|
$MASTERID = $this->quality_model->saveMasterTestData($masterreportdata);
|
|
|
|
|
|
|
|
foreach($testphpdata as $data)
|
|
{
|
|
//print_r($data);die();
|
|
$descrition = $data['Description'];
|
|
$min = $data['SpecificationMin'];
|
|
$max = $data['SpecificationMax'];
|
|
$uom = $data['SpecificationUOM'];
|
|
$act1 = $data['ACT X1'];
|
|
$act2 = $data['ACT X2'];
|
|
$act3 = $data['ACT X3'];
|
|
$average = $data['Average'];
|
|
$results = $data['Results'];
|
|
$remarks1 = $data['Remarks'];
|
|
$testreportdata = array('testreport_id'=>$MASTERID,'description'=>$descrition,'min'=>$min,'max'=>$max,'UOM'=>$uom,'act1'=>$act1,'act2'=>$act2,'act3'=>$act3,'average'=>$average,'result'=>$results,'remarks'=>$remarks1);
|
|
$reportid = $this->quality_model->saveTestReportData($testreportdata);
|
|
}
|
|
|
|
|
|
// $start = '';
|
|
// $end = '';
|
|
// $temp = '';
|
|
// $w1 = '';
|
|
// $w2 = '';
|
|
// $w3 = '';
|
|
// $loip = '';
|
|
// $remark = '';
|
|
foreach($loiphpdata as $loi)
|
|
{
|
|
$start = $loi['Heating Timestart'];
|
|
$end = $loi['Heating Timeend'];
|
|
$temp = $loi['Temp *c'];
|
|
$w1 = $loi['Crucible Weight w1(g)'];
|
|
$w2 = $loi['Before Heatingw2(g)'];
|
|
$w3 = $loi['After Heatingw3(g)'];
|
|
$loip = $loi['L.O.I %'];
|
|
$remark = $loi['Remarks'];
|
|
//echo $loip;
|
|
//echo $remark;die();
|
|
$loitabledata = array('testreport_id'=>$MASTERID,'start_time'=>$start,'end_time'=>$end,'temp'=>$temp,'w1'=>$w1,'w2'=>$w2,'w3'=>$w3,'loi_percentage'=>$loip,'remarks'=>$remark);
|
|
$loiid = $this->quality_model->saveTestReportLOIData($loitabledata);
|
|
|
|
}
|
|
|
|
$count =0;
|
|
foreach($afsphpdata as $afs)
|
|
{
|
|
$count++;
|
|
if($count != 12){
|
|
$ssize = $afs['Sieve Size µm'];
|
|
$mesh_size = $afs['Mesh Size'];
|
|
$sandweight = $afs['Sand Weight'];
|
|
$Percentage = $afs['Percentage'];
|
|
$Multiplier = $afs['Multiplier'];
|
|
$Product = $afs['Product'];
|
|
$afstabledata = array('testreport_id'=>$MASTERID,'sieve_size'=>$ssize,'mesh_size'=>$mesh_size,'sandweight'=>$sandweight,'percentage'=>$Percentage,'multiplier'=>$Multiplier,'product'=>$Product);
|
|
$afsid = $this->quality_model->saveTestReportAFSData($afstabledata);
|
|
}
|
|
}
|
|
|
|
echo "Report Data Saved Successfully!";
|
|
|
|
|
|
}
|
|
|
|
|
|
function addNewInward_Report()
|
|
{
|
|
$data['records'] = $this->quality_model->getIGRNOforReport();
|
|
$data['reports'] = $this->quality_model->getIGRNOReport(); ;
|
|
$data['emplist'] = $this->quality_model->getEmplistforReport();
|
|
$this->global['pageTitle'] = 'Siddharth : Inward Inspection';
|
|
$this->loadViews("inward_report_create", $this->global,$data,NULL);
|
|
|
|
}
|
|
|
|
|
|
function getIGRLineItemNo()
|
|
{
|
|
$igrno = $this->input->post('param1');
|
|
$data['igrdetails'] = $this->quality_model->getIGRLineItemNo($igrno);
|
|
//print_r($data['igrdetails']);
|
|
echo json_encode($data['igrdetails']);
|
|
|
|
}
|
|
|
|
|
|
function getIGRDetails()
|
|
{
|
|
$igrno = $this->input->post('param1');
|
|
$igrlineitemno = $this->input->post('param2');
|
|
$data['igrdetails'] = $this->quality_model->getIGRDataforReport($igrno,$igrlineitemno);
|
|
//print_r($data['igrdetails']);
|
|
echo json_encode($data['igrdetails']);
|
|
}
|
|
|
|
function pageNotFound()
|
|
{
|
|
$this->global['pageTitle'] = 'CodeInsect : 404 - Page Not Found';
|
|
|
|
$this->loadViews("404", $this->global, NULL, NULL);
|
|
}
|
|
|
|
function uploadFile()
|
|
{
|
|
|
|
$pathinfo = pathinfo($_FILES['rfile']['name']);
|
|
$config['upload_path'] = 'uploads/QAD/';
|
|
$config['allowed_types'] = '*';
|
|
$filename = $_FILES['rfile']['name'];
|
|
$ext = end(explode('.',$filename));
|
|
|
|
$ext = strtolower($ext);
|
|
$fn = 'qad' . date('Y-m-d') . time() . '.' . $ext;
|
|
//print_r($fn);die();
|
|
$config['file_name'] = $fn;
|
|
//echo $config['file_name'];
|
|
$this->load->library('upload',$config);
|
|
$this->upload->initialize($config);
|
|
|
|
|
|
if($this->upload->do_upload('rfile'))
|
|
{
|
|
$uploadData = $this->upload->data();
|
|
$uploadfilename = $uploadData['file_name'];
|
|
return $uploadfilename;
|
|
|
|
}
|
|
else
|
|
{
|
|
$error = array('error' => $this->upload->display_errors());
|
|
$uploadfilename = '';
|
|
print_r($error);
|
|
return null;
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// start zoho API
|
|
|
|
function zohobooks_api_fetch_all(){
|
|
try{
|
|
if (isset($_POST['sync']) || $_GET['from'] != null && $_GET['to'] != null)
|
|
{
|
|
// $ch=curl_init();
|
|
$this->load->helper('zohobooks_fetch_api_helper');
|
|
if($_GET['from'] != null && $_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('-1 day',strtotime($date_today)));
|
|
}
|
|
$chk_acc_token_val = $this->Zohobook_model->get_data('zohobook_accesstoken','id' , 1);
|
|
$date = new DateTime($chk_acc_token_val[0]['created_at']); $date->add(new DateInterval('PT1H'));
|
|
$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'); }
|
|
$result = getheringInvoiceDetails($date_today , $date_yesterday , $token);
|
|
// echo json_encode($result);
|
|
$headers_new = $result['headers_new'];
|
|
$res = json_decode($result['data'],true);
|
|
$inv_array = $res['invoices'];
|
|
foreach($inv_array as $inv){
|
|
$invoice_id = $inv['invoice_id'];
|
|
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;
|
|
foreach($res2 as $rs)
|
|
{
|
|
$gst_no = $rs['gst_no'];
|
|
$sku = $rs['line_items'][0]['sku'];
|
|
$invoice_number = $rs['invoice_number'];
|
|
$invoice_date = $rs['date'];
|
|
|
|
$sql_invoice_chk = $this->Zohobook_model->ip_invoices($invoice_number , $invoice_date);
|
|
if($sql_invoice_chk <= 0)
|
|
{
|
|
$gst_no = $rs['gst_no'];
|
|
$sku = $rs['line_items'][0]['sku'];
|
|
$invoice_number = $rs['invoice_number'];
|
|
$invoice_date = $rs['date'];
|
|
$due_date = $rs['due_date'];
|
|
$item_price = $rs['line_items'][0]['rate'];
|
|
$item_order = $rs['line_items'][0]['item_order'];
|
|
$item_product_unit = $rs['line_items'][0]['unit'];
|
|
$item_name = $rs['line_items'][0]['name'];
|
|
$item_description = $rs['line_items'][0]['description'];
|
|
$item_quantity = $rs['line_items'][0]['quantity'];
|
|
// $batch_no = $rs['custom_fields'][5]['value'];
|
|
$batch_no = "";
|
|
$invoice_time=$rs['created_time'];
|
|
$time_array = explode("T", $invoice_time);
|
|
$time_array = explode("+",$time_array[1]);
|
|
$invoice_time = $time_array[0];
|
|
$status = $rs['status'];
|
|
|
|
$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'];
|
|
|
|
$cgst = $rs['taxes'][0]['tax_name'];
|
|
$sgst = $rs['taxes'][1]['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'][0]['item_total'];
|
|
$item_tax_total = $rs['tax_total'];
|
|
$item_total = $rs['total'];
|
|
$item_sgst_amt = $rs['taxes'][1]['tax_amount'];
|
|
$item_cgst_amt = $rs['taxes'][0]['tax_amount'];
|
|
|
|
$item_discount = 0.00;
|
|
$item_igst_amt = 0.00;
|
|
if($batch_no==""){ $batch_no = "";}
|
|
$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);
|
|
}
|
|
|
|
$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);
|
|
}
|
|
|
|
$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'] = 2;
|
|
$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);
|
|
else
|
|
log_message('error', 'Data insert failed DB : ip_invoice_items client id :'. $client_id);
|
|
|
|
$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 ');
|
|
|
|
//custom fields insert
|
|
// 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 ');
|
|
$insert_count = $insert_count + 1;
|
|
}
|
|
else // update invoice status, especially for cancelled invoices
|
|
{
|
|
if($status == "void")
|
|
{
|
|
$sql_invoice_update['invoice_status_id'] = 5;
|
|
$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 . '/'.'cancelled 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
|
|
|
|
|
|
|
|
}
|
|
?>
|