sparqapi/api/application/models/Data_Dump_Model.php

123 lines
5.2 KiB
PHP
Executable File

<?php
defined('BASEPATH') OR exit('No direct script access allowed');
require_once APPPATH . '/libraries/SPARQ_Model.php';
class Data_Dump_Model extends SPARQ_Model {
public function __construct() {
parent::__construct();
}
function saveGenDumpData($gen_data_dump)
{
if(isset($gen_data_dump['individuals_data']))
{
foreach ($gen_data_dump['individuals_data'] as $key => $value)
{
$this->saveRecords($value,D_GENERAL_IND);
}
}
if(isset($gen_data_dump['relationship_data']))
{
foreach ($gen_data_dump['relationship_data'] as $key => $value)
{
$this->saveRecords($value,D_GEN_RELATIONSHIP);
}
}
}
function saveBusinessDUmpData($business_data_dump)
{
print_r($business_data_dump);
echo "*****************";
if(isset($business_data_dump['single_business_items']))
{
$this->saveRecords($business_data_dump['single_business_items'],D_BUSINESS_FORM);
}
if(isset($business_data_dump['partners_details']))
{
foreach ($business_data_dump['partners_details'] as $key => $value)
{
$this->saveRecords($value,D_BUSINESS_PARTNERS);
}
}
if(isset($business_data_dump['type_of_activity_details']))
{
foreach ($business_data_dump['type_of_activity_details'] as $key => $value)
{
$this->saveRecords($value,D_BUSIENSS_TYPE);
}
}
if(isset($business_data_dump['business_relatinship_data']))
{
foreach ($business_data_dump['business_relatinship_data'] as $key => $value)
{
$this->saveRecords($value,D_BUSINESS_RELATINSHIP);
}
}
if(isset($business_data_dump['products']))
{
foreach ($business_data_dump['products'] as $index => $activity_data)
{
foreach ($activity_data as $key => $value)
{
$this->saveRecords($value,D_BUSINESS_PRODUCTS);
}
}
}
}
function getRequestForDataDump($arr){
$pdid = isset($arr['pd_id'])?$arr['pd_id']:[];
$fromd = $arr['from_date'];
$tod= $arr['to_date'];
$type = isset($arr['pd_type_id'])?$arr['pd_type_id']:null;
$prod = isset($arr['product_id'])?$arr['product_id']:null;
$cseg = isset($arr['customer_segment_id'])?$arr['customer_segment_id']:null;
### 2 tables t_pd_form_details_json and t_pd_triggered
$this->db->select('PDFORMDETAILSJSON.pd_form_detail_json_id, PDFORMDETAILSJSON.fk_pd_id, PDFORMDETAILSJSON.fk_form_id, PDFORMDETAILSJSON.isactive, PDFORMDETAILSJSON.json, DATE_FORMAT(PDFORMDETAILSJSON.createdon,"%d/%m/%Y %H:%i:%s") as createdon, PDFORMDETAILSJSON.processed_json, PDFORMDETAILSJSON.updatedon,DATE_FORMAT(PDTRIGGER.completed_on,"%d/%m/%Y %H:%i:%s") as completed_on,PDTRIGGER.fk_product_id, PDTRIGGER.fk_customer_segment,PDTRIGGER.fk_pd_type,PDTRIGGER.pd_status,PDTRIGGER.createdon');
$this->db->from(PDFORMDETAILSJSON.' as PDFORMDETAILSJSON');
$this->db->join(PDTRIGGER.' as PDTRIGGER','PDTRIGGER.pd_id = PDFORMDETAILSJSON.fk_pd_id ','LEFT');
if(!empty($pdid))
{
$this->db->where_in('PDFORMDETAILSJSON.fk_pd_id',$pdid);
}
if(($fromd != "" || $fromd != null) && ($tod != "" || $tod != null)) {
$this->db->where('PDTRIGGER.completed_on BETWEEN '. "'$fromd'". ' AND '. "'$tod'" );
}
else if($fromd != "" && $fromd != null) {
$this->db->where("DATE_FORMAT(PDTRIGGER.completed_on,'%Y-%m-%d')",$fromd);
}
else if($tod != "" && $tod != null) {
$this->db->where("DATE_FORMAT(PDTRIGGER.completed_on,'%Y-%m-%d')",$tod);
}
if($prod != ""){
$this->db->where('PDTRIGGER.fk_product_id',$prod);
}
if($type != ""){
$this->db->where('PDTRIGGER.fk_pd_type',$type);
}
if($cseg != ""){
$this->db->where('PDTRIGGER.fk_customer_segment',$cseg);
}
$this->db->WHERE('PDFORMDETAILSJSON.isactive',1);
$this->db->order_by('PDFORMDETAILSJSON.pd_form_detail_json_id','desc');
$this->db->limit(5);
$result = $this->db->get()->result_array();
// echo count($result);print_r($result);print_r($this->db->last_query());die();
return $result;
}
public function filtermasterfordatadumprequest(){
$result['pdtype'] = $this->db->select('PDTYPE.pd_type_id,PDTYPE.type_name')->from(PDTYPE.' as PDTYPE')->WHERE('PDTYPE.isactive',1)->GET()->result_array();
$result['product'] = $this->db->select('PRODUCTS.product_id,PRODUCTS.name,PRODUCTS.abbr')->from(PRODUCTS.' as PRODUCTS')->WHERE('PRODUCTS.isactive',1)->GET()->result_array();
$result['customersegment'] = $this->db->select('CUSTOMERSEGMENT.customer_segment_id,CUSTOMERSEGMENT.name,CUSTOMERSEGMENT.abbr')->from(CUSTOMERSEGMENT.' as CUSTOMERSEGMENT')->WHERE('CUSTOMERSEGMENT.isactive',1)->GET()->result_array();
$result['pdid'] = $this->db->select('PDTRIGGER.pd_sno,PDTRIGGER.pd_id')->from(PDTRIGGER.' as PDTRIGGER')->WHERE('PDTRIGGER.pd_status !=',"TRUNCATED")->GET()->result_array();
return $result;
}
}