Advertisement
Guest User

Untitled

a guest
Sep 13th, 2018
523
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 194.60 KB | None | 0 0
  1. <?php
  2. /**
  3.  * Classe para manipular os logs da dashboard
  4.  *
  5.  * @author Gabriel Moraes <gabriel.baptista@inside-estudio.com.br>
  6.  */
  7. namespace App\Http\Controllers\Sync;
  8.  
  9. use Illuminate\Http\Request;
  10. use App\Http\Controllers\Controller;
  11. use Illuminate\Support\Facades\DB;
  12. use App\Utils\ApiResponse;
  13. use App\Utils\DatabaseUtils;
  14. use App\Utils\GetFile;
  15. use Carbon\Carbon;
  16. use \PDO;
  17.  
  18.  
  19.  
  20. class SyncController extends Controller
  21. {
  22.  
  23.     private $address;
  24.    
  25.     private function downloadImage($image)
  26.     {
  27.         $gf = new GetFile($this->address);
  28.        
  29.         $gf->download($image);
  30.     }
  31.        
  32.     /**
  33.      * Método utilizado para sincronizar os bancos de dados
  34.      * @param  Request $request [description]
  35.      * @return [type]           [description]
  36.      */
  37.     public function sync(Request $request)
  38.     {
  39.         $data = $request->all();
  40.        
  41.         $companyId = $data['items']['id_company'];
  42.        
  43.         $this->address = $data['address'];
  44.        
  45.         $updateNewItems = $this->updateNewItems($data['update_new']);
  46.        
  47.         $verifySync = $this->insertIntoOnline($data['items']);
  48.        
  49.         $selectSync             = $this->selectNoSync($companyId);
  50.         $returnSelect['items']  = $selectSync;
  51.         $returnSelect['insert'] = $verifySync;
  52.         // print_r($returnSelect['insert']);die();
  53.        
  54.         return json_encode($returnSelect);
  55.     }
  56.    
  57.    
  58.     public function syncNewItems(Request $request)
  59.     {
  60.         $data      = $request->all();
  61.         $companyId = $data['id_company'];
  62.        
  63.        
  64.         $list = $this->selectNeverSync($companyId);
  65.         return json_encode($list);
  66.         // return json_encode($list, JSON_PRETTY_PRINT);
  67.     }
  68.     /**
  69.      * Método utilizado para sincronizar dados que foram inseridos na off  para online
  70.      * @param  [type] $decodedResponse [description]
  71.      * @return [type]                  [description]
  72.      */
  73.     public function updateNewItems($decodedResponse) {
  74.         $conn = DatabaseUtils::getDB();
  75.         $conn->beginTransaction();
  76.         try {
  77.             //ADICIONAIS
  78.             foreach ($decodedResponse['additionals'] as $additional) {
  79.                
  80.                 $insertAdditional = $conn->prepare('UPDATE `additional` SET id_additional_off = :id_off , sync = :sync WHERE id = :online_id');
  81.                 $insertAdditional->bindValue(':online_id', $additional['online_id']);
  82.                 $insertAdditional->bindValue(':id_off', $additional['id_off']);
  83.                 $insertAdditional->bindValue(':sync', 'yes');
  84.                
  85.                 $insertAdditional->execute();
  86.             }
  87.             //CATEGORIAS
  88.             foreach ($decodedResponse['category'] as $category) {
  89.                 $insertCategory = $conn->prepare('UPDATE `category` SET sync = :sync, id_category_off = :id_off WHERE id = :online_id');
  90.                 $insertCategory->bindValue(':id_off', $category['id_off']);
  91.                 $insertCategory->bindValue(':online_id', $category['online_id']);
  92.                 $insertCategory->bindValue(':sync', 'yes');
  93.                
  94.                 $insertCategory->execute();
  95.             }
  96.             //CATEGORIAS EXIBIÇÃO
  97.             foreach ($decodedResponse['category_exibition'] as $category_exibition) {
  98.                
  99.                 $insertCategoryExibition = $conn->prepare('UPDATE `category_exibition` SET sync = :sync, id_category_exibition_off = :id_off WHERE id = :online_id');
  100.                 $insertCategoryExibition->bindValue(':online_id', $category_exibition['online_id']);
  101.                 $insertCategoryExibition->bindValue(':id_off', $category_exibition['id_off']);
  102.                 $insertCategoryExibition->bindValue(':sync', 'yes');
  103.                
  104.                 $insertCategoryExibition->execute();
  105.             }
  106.            
  107.             foreach ($decodedResponse['command'] as $command) {
  108.                
  109.                 $insertCommand = $conn->prepare('UPDATE `command` SET sync = :sync, id_command_off = :id_off WHERE id = :online_id');
  110.                 $insertCommand->bindValue(':id_off', $command['id_off']);
  111.                 $insertCommand->bindValue(':online_id', $command['online_id']);
  112.                 $insertCommand->bindValue(':sync', 'yes');
  113.                
  114.                 $insertCommand->execute();
  115.             }
  116.            
  117.             foreach ($decodedResponse['config'] as $user) {
  118.                
  119.                 $insertUser = $conn->prepare('UPDATE `config` SET id_config_off = :id_off, sync = :sync WHERE id = :online_id');
  120.                 $insertUser->bindValue(':online_id', $user['online_id']);
  121.                 $insertUser->bindValue(':id_off', $user['id_off']);
  122.                 $insertUser->bindValue(':sync', 'yes');
  123.                 $insertUser->execute();
  124.             }
  125.            
  126.             foreach ($decodedResponse['company_user'] as $user) {
  127.                
  128.                 $insertUser = $conn->prepare('UPDATE `company_user` SET id_company_user_off = :id_off, sync = :sync WHERE id = :online_id');
  129.                 $insertUser->bindValue(':online_id', $user['online_id']);
  130.                 $insertUser->bindValue(':id_off', $user['id_off']);
  131.                 $insertUser->bindValue(':sync', 'yes');
  132.                 $insertUser->execute();
  133.             }
  134.            
  135.             foreach ($decodedResponse['menu'] as $menuType) {
  136.                
  137.                 $insertMenuType = $conn->prepare('UPDATE`menu_type` SET sync = :sync, id_menu_type_off = :id_off WHERE id = :online_id');
  138.                 $insertMenuType->bindValue(':online_id', $menuType['online_id']);
  139.                 $insertMenuType->bindValue(':id_off', $menuType['id_off']);
  140.                 $insertMenuType->bindValue(':sync', 'yes');
  141.                
  142.                 $insertMenuType->execute();
  143.             }
  144.            
  145.             foreach ($decodedResponse['company_log'] as $log) {
  146.                
  147.                 $insertLog = $conn->prepare('UPDATE `company_log` SET sync = :sync, id_log_off = :id_off WHERE id = :online_id');
  148.                 $insertLog->bindValue(':online_id', $log['online_id']);
  149.                 $insertLog->bindValue(':id_off', $log['id_off']);
  150.                 $insertLog->bindValue(':sync', 'yes');
  151.                
  152.                 $insertLog->execute();
  153.             }
  154.            
  155.             foreach ($decodedResponse['preference'] as $preference) {
  156.                
  157.                 $insertPreference = $conn->prepare('UPDATE `preference` SET id_preference_off = :id_off, sync = :sync WHERE id = :online_id');
  158.                 $insertPreference->bindValue(':online_id', $preference['online_id']);
  159.                 $insertPreference->bindValue(':id_off', $preference['id_off']);
  160.                 $insertPreference->bindValue(':sync', 'yes');
  161.                
  162.                 $insertPreference->execute();
  163.             }
  164.            
  165.             foreach ($decodedResponse['preference_category'] as $preference) {
  166.                
  167.                 $insertPreference = $conn->prepare('UPDATE`preference_category` SET sync = :sync, id_preference_category_off = :id_off WHERE id = :online_id');
  168.                 $insertPreference->bindValue(':online_id', $preference['online_id']);
  169.                 $insertPreference->bindValue(':id_off', $preference['id_off']);
  170.                 $insertPreference->bindValue(':sync', 'yes');
  171.                
  172.                 $insertPreference->execute();
  173.             }
  174.            
  175.             foreach ($decodedResponse['preference_item'] as $preference) {
  176.                
  177.                 $insertPreference = $conn->prepare('UPDATE `preference_item` SET sync = :sync, id_preference_item_off = :id_off WHERE id = :online_id');
  178.                 $insertPreference->bindValue(':online_id', $preference['online_id']);
  179.                 $insertPreference->bindValue(':id_off', $preference['id_off']);
  180.                 $insertPreference->bindValue(':sync', 'yes');
  181.                
  182.                 $insertPreference->execute();
  183.             }
  184.            
  185.             foreach ($decodedResponse['products'] as $product) {
  186.                
  187.                 $insertProduct = $conn->prepare('UPDATE `product` SET sync = :sync, id_product_off = :id_off WHERE id = :online_id');
  188.                 $insertProduct->bindValue(':online_id', $product['online_id']);
  189.                 $insertProduct->bindValue(':id_off', $product['id_off']);
  190.                 $insertProduct->bindValue(':sync', 'yes');
  191.                
  192.                 $insertProduct->execute();
  193.             }
  194.            
  195.             foreach ($decodedResponse['product_additionals'] as $product) {
  196.                
  197.                 $insertProduct = $conn->prepare('UPDATE `product_additional` SET sync = :sync, id_product_additional_off = :id_off WHERE id = :online_id');
  198.                 $insertProduct->bindValue(':online_id', $product['online_id']);
  199.                 $insertProduct->bindValue(':id_off', $product['id_off']);
  200.                 $insertProduct->bindValue(':sync', 'yes');
  201.                
  202.                 $insertProduct->execute();
  203.             }
  204.            
  205.             foreach ($decodedResponse['product_category'] as $product) {
  206.                
  207.                 $insertProduct = $conn->prepare('UPDATE `product_category` SET sync = :sync, id_product_category_off = :id_off WHERE id = :online_id');
  208.                 $insertProduct->bindValue(':online_id', $product['online_id']);
  209.                 $insertProduct->bindValue(':id_off', $product['id_off']);
  210.                 $insertProduct->bindValue(':sync', 'yes');
  211.                
  212.                 $insertProduct->execute();
  213.             }
  214.            
  215.             //PRODUTOS EXIBIÇÃO
  216.             foreach ($decodedResponse['product_exibition'] as $product_exibition) {
  217.                
  218.                 $insertProductExibition = $conn->prepare('UPDATE `product_exibition` SET sync = :sync, id_product_exibition_off = :id_off WHERE id = :online_id');
  219.                 $insertProductExibition->bindValue(':online_id', $product_exibition['online_id']);
  220.                 $insertProductExibition->bindValue(':id_off', $product_exibition['id_off']);
  221.                 $insertProductExibition->bindValue(':sync', 'yes');
  222.                
  223.                 $insertProductExibition->execute();
  224.             }
  225.            
  226.             foreach ($decodedResponse['product_image'] as $product_exibition) {
  227.                
  228.                 $insertProductImage = $conn->prepare('UPDATE `product_image` SET sync = :sync, id_product_image_off = :id_off WHERE id = :online_id');
  229.                 $insertProductImage->bindValue(':online_id', $product_exibition['online_id']);
  230.                 $insertProductImage->bindValue(':id_off', $product_exibition['id_off']);
  231.                 $insertProductImage->bindValue(':sync', 'yes');
  232.                
  233.                 $insertProductImage->execute();
  234.             }
  235.            
  236.             foreach ($decodedResponse['product_preference'] as $product) {
  237.                
  238.                 $productPreference = $conn->prepare('UPDATE `product_preference` SET sync = :sync, id_product_preference_off = :id_off WHERE id = :online_id');
  239.                 $productPreference->bindValue(':online_id', $product['online_id']);
  240.                 $productPreference->bindValue(':id_off', $product['id_off']);
  241.                 $productPreference->bindValue(':sync', 'yes');
  242.                
  243.                 $productPreference->execute();
  244.             }
  245.            
  246.             foreach ($decodedResponse['product_types'] as $product) {
  247.                
  248.                 $productPreference = $conn->prepare('UPDATE `product_type` SET sync = :sync, id_product_type_off = :id_off WHERE id = :online_id');
  249.                 $productPreference->bindValue(':online_id', $product['online_id']);
  250.                 $productPreference->bindValue(':id_off', $product['id_off']);
  251.                 $productPreference->bindValue(':sync', 'yes');
  252.                
  253.                 $productPreference->execute();
  254.             }
  255.            
  256.             foreach ($decodedResponse['sale_type'] as $sale) {
  257.                
  258.                 $saleType = $conn->prepare('UPDATE `sale_type` SET sync = :sync, id_sale_type_off = :id_off WHERE id = :online_id');
  259.                 $saleType->bindValue(':online_id', $sale['online_id']);
  260.                 $saleType->bindValue(':id_off', $sale['id_off']);
  261.                 $saleType->bindValue(':sync', 'yes');
  262.                
  263.                 $saleType->execute();
  264.             }
  265.            
  266.             foreach ($decodedResponse['product_sales'] as $product) {
  267.                
  268.                 $productPreference = $conn->prepare('UPDATE `product_sale` SET sync = :sync, id_product_sale_off = :id_off WHERE id = :online_id');
  269.                 $productPreference->bindValue(':online_id', $product['online_id']);
  270.                 $productPreference->bindValue(':id_off', $product['id_off']);
  271.                 $productPreference->bindValue(':sync', 'yes');
  272.                
  273.                 $productPreference->execute();
  274.             }
  275.            
  276.             foreach ($decodedResponse['table'] as $table) {
  277.                
  278.                 $insertTable = $conn->prepare('UPDATE `table` SET sync = :sync, id_table_off = :id_off WHERE id = :online_id');
  279.                 $insertTable->bindValue(':online_id', $table['online_id']);
  280.                 $insertTable->bindValue(':id_off', $table['id_off']);
  281.                 $insertTable->bindValue(':sync', 'yes');
  282.                
  283.                 $insertTable->execute();
  284.             }
  285.            
  286.             foreach ($decodedResponse['command_table'] as $command_table) {
  287.                
  288.                 $insertCommandTable = $conn->prepare('UPDATE `command_table` SET sync = :sync, id_command_table_off = :id_off WHERE id = :online_id');
  289.                 $insertCommandTable->bindValue(':online_id', $command_table['online_id']);
  290.                 $insertCommandTable->bindValue(':id_off', $command_table['id_off']);
  291.                 $insertCommandTable->bindValue(':sync', 'yes');
  292.                
  293.                 $insertCommandTable->execute();
  294.             }
  295.            
  296.             foreach ($decodedResponse['tag'] as $table) {
  297.                
  298.                 $insertTable = $conn->prepare('UPDATE `tag` SET sync = :sync WHERE id = :online_id');
  299.                 $insertTable->bindValue(':online_id', $table['online_id']);
  300.                 $insertTable->bindValue(':sync', 'yes');
  301.                
  302.                 $insertTable->execute();
  303.             }
  304.            
  305.             foreach ($decodedResponse['product_tags'] as $product) {
  306.                
  307.                 $productPreference = $conn->prepare('UPDATE `product_tag` SET sync = :sync, id_product_tag_off = :id_off WHERE id = :online_id');
  308.                 $productPreference->bindValue(':online_id', $product['online_id']);
  309.                 $productPreference->bindValue(':id_off', $product['id_off']);
  310.                 $productPreference->bindValue(':sync', 'yes');
  311.                
  312.                 $productPreference->execute();
  313.             }
  314.            
  315.             foreach ($decodedResponse['target'] as $table) {
  316.                
  317.                 $insertTable = $conn->prepare('UPDATE `target_audience` SET sync = :sync WHERE id = :online_id');
  318.                 $insertTable->bindValue(':online_id', $table['online_id']);
  319.                 $insertTable->bindValue(':sync', 'yes');
  320.                
  321.                 $insertTable->execute();
  322.             }
  323.            
  324.             foreach ($decodedResponse['combo'] as $combo) {
  325.                
  326.                 $insertCombo = $conn->prepare('UPDATE `combo` SET sync = :sync, id_combo_off = :id_off WHERE id = :online_id');
  327.                 $insertCombo->bindValue(':online_id', $combo['online_id']);
  328.                 $insertCombo->bindValue(':id_off', $combo['id_off']);
  329.                 $insertCombo->bindValue(':sync', 'yes');
  330.                
  331.                 $insertCombo->execute();
  332.             }
  333.            
  334.             foreach ($decodedResponse['combo_group'] as $combo_group) {
  335.                
  336.                 $insertComboGroup = $conn->prepare('UPDATE `combo_group` SET sync = :sync, id_combo_group_off = :id_off WHERE id = :online_id');
  337.                 $insertComboGroup->bindValue(':online_id', $combo_group['online_id']);
  338.                 $insertComboGroup->bindValue(':id_off', $combo_group['id_off']);
  339.                 $insertComboGroup->bindValue(':sync', 'yes');
  340.                
  341.                 $insertComboGroup->execute();
  342.             }
  343.            
  344.             foreach ($decodedResponse['combo_group_item'] as $combo_group) {
  345.                
  346.                 $insertComboGroup = $conn->prepare('UPDATE `combo_group_item` SET sync = :sync, id_combo_group_item_off = :id_off WHERE id = :online_id');
  347.                 $insertComboGroup->bindValue(':online_id', $combo_group['online_id']);
  348.                 $insertComboGroup->bindValue(':id_off', $combo_group['id_off']);
  349.                 $insertComboGroup->bindValue(':sync', 'yes');
  350.                
  351.                 $insertComboGroup->execute();
  352.             }
  353.            
  354.             foreach ($decodedResponse['combo_type'] as $combo_group) {
  355.                
  356.                 $insertComboGroup = $conn->prepare('UPDATE `combo_type` SET sync = :sync, id_combo_type_off = :id_off WHERE id = :online_id');
  357.                 $insertComboGroup->bindValue(':online_id', $combo_group['online_id']);
  358.                 $insertComboGroup->bindValue(':id_off', $combo_group['id_off']);
  359.                 $insertComboGroup->bindValue(':sync', 'yes');
  360.                
  361.                 $insertComboGroup->execute();
  362.             }
  363.            
  364.             foreach ($decodedResponse['combo_image'] as $combo_group) {
  365.                
  366.                 $insertComboGroup = $conn->prepare('UPDATE `combo_image` SET sync = :sync, id_combo_image_off = :id_off WHERE id = :online_id');
  367.                 $insertComboGroup->bindValue(':online_id', $combo_group['online_id']);
  368.                 $insertComboGroup->bindValue(':id_off', $combo_group['id_off']);
  369.                 $insertComboGroup->bindValue(':sync', 'yes');
  370.                
  371.                 $insertComboGroup->execute();
  372.             }
  373.            
  374.             foreach ($decodedResponse['combo_exibition'] as $combo_group) {
  375.                
  376.                 $insertComboGroup = $conn->prepare('UPDATE `combo_exibition` SET sync = :sync, id_combo_exibition_off = :id_off WHERE id = :online_id');
  377.                 $insertComboGroup->bindValue(':online_id', $combo_group['online_id']);
  378.                 $insertComboGroup->bindValue(':id_off', $combo_group['id_off']);
  379.                 $insertComboGroup->bindValue(':sync', 'yes');
  380.                
  381.                 $insertComboGroup->execute();
  382.             }
  383.            
  384.             //INSERE AS CAMPANHAS
  385.             foreach ($decodedResponse['campaign'] as $campaign) {
  386.                
  387.                 $insertCampaign = $conn->prepare('UPDATE `campaign` SET sync = :sync WHERE id = :online_id');
  388.                 $insertCampaign->bindValue(':online_id', $campaign['online_id']);
  389.                 $insertCampaign->bindValue(':sync', 'yes');
  390.                
  391.                 $insertCampaign->execute();
  392.             }
  393.             //INSERE AS CAMPANHAS NAS EMPRESAS
  394.             foreach ($decodedResponse['campaign_company'] as $campaign) {
  395.                 $insertCampaign = $conn->prepare('UPDATE `campaign_company` SET sync = :sync WHERE id = :online_id');
  396.                 $insertCampaign->bindValue(':online_id', $campaign['online_id']);
  397.                 $insertCampaign->bindValue(':sync', 'yes');
  398.                
  399.                 $insertCampaign->execute();
  400.             }
  401.            
  402.            
  403.             //INSERE AS CAMPANHAS DAS EMPRESAS
  404.             foreach ($decodedResponse['restaurant_campaign'] as $campaign) {
  405.                
  406.                 $insertCampaign = $conn->prepare('UPDATE `restaurant_campaign` SET sync = :sync, id_restaurant_campaign_off = :id_off WHERE id = :online_id');
  407.                 $insertCampaign->bindValue(':online_id', $campaign['online_id']);
  408.                 $insertCampaign->bindValue(':id_off', $campaign['id_off']);
  409.                 $insertCampaign->bindValue(':sync', 'yes');
  410.                
  411.                 $insertCampaign->execute();
  412.             }
  413.            
  414.             //INSERE AS CAMPANHAS DAS EMPRESAS
  415.             foreach ($decodedResponse['restaurant_campaign_product'] as $campaign) {
  416.                
  417.                 $insertCampaign = $conn->prepare('UPDATE `restaurant_campaign_product` SET sync = :sync, id_restaurant_campaign_product_off = :id_off WHERE id = :online_id');
  418.                 $insertCampaign->bindValue(':online_id', $campaign['online_id']);
  419.                 $insertCampaign->bindValue(':id_off', $campaign['id_off']);
  420.                 $insertCampaign->bindValue(':sync', 'yes');
  421.                
  422.                 $insertCampaign->execute();
  423.             }
  424.            
  425.             $conn->commit();
  426.             $list['error'] = 'false';
  427.             return $list;
  428.         }
  429.         catch (Exception $e) {
  430.             $list['error'] = 'true';
  431.             $conn->rollBack();
  432.             return $list;
  433.         }
  434.     }
  435.    
  436.     /**
  437.      * Método utilizado para inserir ou atualizar dados da off na online
  438.      * @param  [type] $decodedResponse [description]
  439.      * @return [type]                  [description]
  440.      */
  441.     public function insertIntoOnline($decodedResponse)
  442.     {
  443.         $conn = DatabaseUtils::getDB();
  444.         $conn->beginTransaction();
  445.        
  446.         try {
  447.             foreach ($decodedResponse['evaluation'] as $avaliation) {
  448.                 if ($avaliation['sync'] == 'never') {
  449.                     $insertEvaluation = $conn->prepare('INSERT INTO `avaliation` (id_company,id_avaliation_off,name,drink,food,music,environment,attendance,description,email,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id,:name,:drink,:food,:music,:environment,:attendance,:description,:email,:sync,:created_at,:updated_at,:deleted_at)');
  450.                     $insertEvaluation->bindValue(':id_company', $avaliation['id_company']);
  451.                     $insertEvaluation->bindValue(':id', $avaliation['id']);
  452.                     $insertEvaluation->bindValue(':name', $avaliation['name']);
  453.                     $insertEvaluation->bindValue(':drink', $avaliation['drink']);
  454.                     $insertEvaluation->bindValue(':food', $avaliation['food']);
  455.                     $insertEvaluation->bindValue(':music', $avaliation['music']);
  456.                     $insertEvaluation->bindValue(':environment', $avaliation['environment']);
  457.                     $insertEvaluation->bindValue(':attendance', $avaliation['attendance']);
  458.                     $insertEvaluation->bindValue(':description', $avaliation['description']);
  459.                     $insertEvaluation->bindValue(':email', $avaliation['email']);
  460.                     $insertEvaluation->bindValue(':sync', 'yes');
  461.                     $insertEvaluation->bindValue(':deleted_at', $avaliation['deleted_at']);
  462.                     $insertEvaluation->bindValue(':created_at', $avaliation['created_at']);
  463.                     $insertEvaluation->bindValue(':updated_at', $avaliation['updated_at']);
  464.                    
  465.                     $insertEvaluation->execute();
  466.                    
  467.                 } else {
  468.                     $insertEvaluation = $conn->prepare('UPDATE `avaliation` SET name = :name, drink = :drink, food = :food, music = :music, environment = :environment, attendance = :attendance, description = :description, email = :email, sync = :sync, created_at = :created_at, updated_at = :updated_at, deleted_at = :deleted_at WHERE id_company = :id_company and id_avaliation_off = :id');
  469.                     $insertEvaluation->bindValue(':id_company', $avaliation['id_company']);
  470.                     $insertEvaluation->bindValue(':id', $avaliation['id']);
  471.                     $insertEvaluation->bindValue(':name', $avaliation['name']);
  472.                     $insertEvaluation->bindValue(':drink', $avaliation['drink']);
  473.                     $insertEvaluation->bindValue(':food', $avaliation['food']);
  474.                     $insertEvaluation->bindValue(':music', $avaliation['music']);
  475.                     $insertEvaluation->bindValue(':environment', $avaliation['environment']);
  476.                     $insertEvaluation->bindValue(':attendance', $avaliation['attendance']);
  477.                     $insertEvaluation->bindValue(':description', $avaliation['description']);
  478.                     $insertEvaluation->bindValue(':email', $avaliation['email']);
  479.                     $insertEvaluation->bindValue(':sync', 'yes');
  480.                     $insertEvaluation->bindValue(':deleted_at', $avaliation['deleted_at']);
  481.                     $insertEvaluation->bindValue(':created_at', $avaliation['created_at']);
  482.                     $insertEvaluation->bindValue(':updated_at', $avaliation['updated_at']);
  483.                    
  484.                     $insertEvaluation->execute();
  485.                 }
  486.             }
  487.            
  488.             foreach ($decodedResponse['additionals'] as $additional) {
  489.                 if ($additional['sync'] == 'never') {
  490.                     $insertAdditional = $conn->prepare('INSERT INTO `additional` (id_company, id_additional_off, name, description, price, image, status, sync,created_at,updated_at,deleted_at) VALUES (:id_company, :id_additional_off, :name, :description, :price, :image, :status,:sync, :created_at, :updated_at, :deleted_at)');
  491.                     $insertAdditional->bindValue(':id_company', $additional['id_company']);
  492.                     $insertAdditional->bindValue(':id_additional_off', $additional['id']);
  493.                     $insertAdditional->bindValue(':name', $additional['name']);
  494.                     $insertAdditional->bindValue(':description', $additional['description']);
  495.                     $insertAdditional->bindValue(':price', $additional['price']);
  496.                     $insertAdditional->bindValue(':image', $additional['image']);
  497.                     $insertAdditional->bindValue(':status', $additional['status']);
  498.                     $insertAdditional->bindValue(':sync', 'yes');
  499.                     $insertAdditional->bindValue(':deleted_at', $additional['deleted_at']);
  500.                     $insertAdditional->bindValue(':created_at', $additional['created_at']);
  501.                     $insertAdditional->bindValue(':updated_at', $additional['updated_at']);
  502.                    
  503.                    
  504.                     $insertAdditional->execute();
  505.                     $arrayAdditional['id_off']    = $conn->lastInsertId();
  506.                     $arrayAdditional['online_id'] = $additional['id'];
  507.                     $arrayAdditionalOnlineId[]    = $additional['id'];
  508.                     $arrayAdditionalOffId[]       = $arrayAdditional['id_off'];
  509.                     $objectAddtional[]            = $arrayAdditional;
  510.                    
  511.                    
  512.                 } else {
  513.                     $insertAdditional = $conn->prepare('UPDATE `additional` SET name = :name, description = :description, price = :price, image = :image, status = :status, sync = :sync,created_at = :created_at,updated_at = :updated_at, deleted_at = :deleted_at WHERE id_company = :id_company and id_additional_off = :id_additional_off');
  514.                     $insertAdditional->bindValue(':id_company', $additional['id_company']);
  515.                     $insertAdditional->bindValue(':id_additional_off', $additional['id']);
  516.                     $insertAdditional->bindValue(':name', $additional['name']);
  517.                     $insertAdditional->bindValue(':description', $additional['description']);
  518.                     $insertAdditional->bindValue(':price', $additional['price']);
  519.                     $insertAdditional->bindValue(':image', $additional['image']);
  520.                     $insertAdditional->bindValue(':status', $additional['status']);
  521.                     $insertAdditional->bindValue(':sync', 'yes');
  522.                     $insertAdditional->bindValue(':deleted_at', $additional['deleted_at']);
  523.                     $insertAdditional->bindValue(':created_at', $additional['created_at']);
  524.                     $insertAdditional->bindValue(':updated_at', $additional['updated_at']);
  525.                    
  526.                     $insertAdditional->execute();
  527.                     $arrayAdditional['id_off']    = $conn->lastInsertId();
  528.                     $arrayAdditional['online_id'] = $additional['id'];
  529.                     $arrayAdditionalOnlineId[]    = $additional['id'];
  530.                     $arrayAdditionalOffId[]       = $arrayAdditional['id_off'];
  531.                     $objectAddtional[]            = $arrayAdditional;
  532.                 }
  533.                
  534.                 if (!empty($additional['image'])) {
  535.                     $this->downloadImage($additional['image']);
  536.                 }
  537.             }
  538.            
  539.             foreach ($decodedResponse['category'] as $category) {
  540.                
  541.                 if ($category['sync'] == 'never') {
  542.                    
  543.                     $insertCategory = $conn->prepare('INSERT INTO `category` (`id_company`, `id_category_off`, `name`, `image`, `status`, `order`, `sync`, `created_at`, `updated_at`, `deleted_at`) VALUES (:id_company, :id_category_off, :name, :image, :status, :order, :sync, :created_at, :updated_at, :deleted_at)');
  544.                     $insertCategory->bindValue(':id_company', $category['id_company']);
  545.                     $insertCategory->bindValue(':id_category_off', $category['id']);
  546.                     $insertCategory->bindValue(':name', $category['name']);
  547.                     $insertCategory->bindValue(':image', $category['image']);
  548.                     $insertCategory->bindValue(':status', $category['status']);
  549.                     $insertCategory->bindValue(':order', $category['order']);
  550.                     $insertCategory->bindValue(':sync', 'yes');
  551.                     $insertCategory->bindValue(':deleted_at', $category['deleted_at']);
  552.                     $insertCategory->bindValue(':created_at', $category['created_at']);
  553.                     $insertCategory->bindValue(':updated_at', $category['updated_at']);
  554.                    
  555.                     $insertCategory->execute();
  556.                     // $arrayCategory['id_off'] = $conn->lastInsertId();
  557.                     // $arrayCategory['online_id'] = $category['id'];
  558.                     // $arrayCategoryOnlineId[] = $category['id'];
  559.                     // $categoryOnlineId = $category['id'];
  560.                     // $categoryoffId = $arrayCategory['id_off'];
  561.                     // $arrayCategoryOffId[] = $arrayCategory['id_off'] ;
  562.                     // $objectCategory[] = $arrayCategory;
  563.                    
  564.                 } else {
  565.                    
  566.                     $insertCategory = $conn->prepare('UPDATE `category` SET `name` = :name, `image` = :image, `status` = :status,`order` = :order , `sync` = :sync, `created_at` = :created_at, `updated_at` = :updated_at, `deleted_at` = :deleted_at WHERE `id_company` = :id_company and `id_category_off` = :id_category_off');
  567.                     $insertCategory->bindValue(':id_company', $category['id_company']);
  568.                     $insertCategory->bindValue(':id_category_off', $category['id']);
  569.                     $insertCategory->bindValue(':name', $category['name']);
  570.                     $insertCategory->bindValue(':image', $category['image']);
  571.                     $insertCategory->bindValue(':status', $category['status']);
  572.                     $insertCategory->bindValue(':order', $category['order']);
  573.                     $insertCategory->bindValue(':sync', 'yes');
  574.                     $insertCategory->bindValue(':deleted_at', $category['deleted_at']);
  575.                     $insertCategory->bindValue(':created_at', $category['created_at']);
  576.                     $insertCategory->bindValue(':updated_at', $category['updated_at']);
  577.                    
  578.                     $insertCategory->execute();
  579.                     $arrayCategory['id_off']    = $conn->lastInsertId();
  580.                     $arrayCategory['online_id'] = $category['id'];
  581.                     $arrayCategoryOnlineId[]    = $category['id'];
  582.                     $categoryOnlineId           = $category['id'];
  583.                     $categoryoffId              = $arrayCategory['id_off'];
  584.                     $arrayCategoryOffId[]       = $arrayCategory['id_off'];
  585.                     $objectCategory[]           = $arrayCategory;
  586.                 }
  587.                
  588.                 if (!empty($category['image'])) {
  589.                     $this->downloadImage($category['image']);
  590.                 }
  591.             }
  592.            
  593.             foreach ($decodedResponse['category_exibition'] as $category_exibition) {
  594.                 $selectCategory = $conn->prepare('SELECT id from category where id_company = :id_company and id_category_off = :id_category_off');
  595.                 $selectCategory->bindValue(':id_company', $category_exibition['id_company']);
  596.                 $selectCategory->bindValue(':id_category_off', $category_exibition['id_category']);
  597.                
  598.                 $selectCategory->execute();
  599.                 $categoryId = $selectCategory->fetch(PDO::FETCH_ASSOC);
  600.                
  601.                 if ($category_exibition['sync'] == 'never') {
  602.                     $insertCategoryExibition = $conn->prepare('INSERT INTO `category_exibition` (id_company,id_category_exibition_off,id_category,day,`at`,`to`,display,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_category_exibition_off,:id_category,:day,:at,:to,:display,:sync,:created_at,:updated_at,:deleted_at)');
  603.                    
  604.                     $insertCategoryExibition->bindValue(':id_company', $category_exibition['id_company']);
  605.                     $insertCategoryExibition->bindValue(':id_category_exibition_off', $category_exibition['id']);
  606.                     $insertCategoryExibition->bindValue(':id_category', $categoryId['id']);
  607.                     $insertCategoryExibition->bindValue(':day', $category_exibition['day']);
  608.                     $insertCategoryExibition->bindValue(':at', $category_exibition['at']);
  609.                     $insertCategoryExibition->bindValue(':to', $category_exibition['to']);
  610.                     $insertCategoryExibition->bindValue(':display', $category_exibition['display']);
  611.                     $insertCategoryExibition->bindValue(':sync', 'yes');
  612.                     $insertCategoryExibition->bindValue(':deleted_at', $category_exibition['deleted_at']);
  613.                     $insertCategoryExibition->bindValue(':created_at', $category_exibition['created_at']);
  614.                     $insertCategoryExibition->bindValue(':updated_at', $category_exibition['updated_at']);
  615.                    
  616.                     $insertCategoryExibition->execute();
  617.                     // $arrayCategory['id_off'] = $conn->lastInsertId();
  618.                     // $arrayCategory['online_id'] = $category_exibition['id'];
  619.                     // $objectCategoryExibition[] = $arrayCategory;
  620.                    
  621.                 } else {
  622.                     $insertCategoryExibition = $conn->prepare('UPDATE `category_exibition` SET id_category = :id_category_off, day = :day,`at` = :at,`to` = :to,display = :display,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_company = :id_company and id_category_exibition_off = :id_category_exibition_off');
  623.                    
  624.                     $insertCategoryExibition->bindValue(':id_company', $category_exibition['id_company']);
  625.                     $insertCategoryExibition->bindValue(':id_category_off', $categoryId['id']);
  626.                     $insertCategoryExibition->bindValue(':id_category_exibition_off', $category_exibition['id']);
  627.                     $insertCategoryExibition->bindValue(':day', $category_exibition['day']);
  628.                     $insertCategoryExibition->bindValue(':at', $category_exibition['at']);
  629.                     $insertCategoryExibition->bindValue(':to', $category_exibition['to']);
  630.                     $insertCategoryExibition->bindValue(':display', $category_exibition['display']);
  631.                     $insertCategoryExibition->bindValue(':sync', 'yes');
  632.                     $insertCategoryExibition->bindValue(':deleted_at', $category_exibition['deleted_at']);
  633.                     $insertCategoryExibition->bindValue(':created_at', $category_exibition['created_at']);
  634.                     $insertCategoryExibition->bindValue(':updated_at', $category_exibition['updated_at']);
  635.                    
  636.                     $insertCategoryExibition->execute();
  637.                     // $arrayCategory['id_off'] = $conn->lastInsertId();
  638.                     // $arrayCategory['online_id'] = $category_exibition['id'];
  639.                     // $objectCategoryExibition[] = $arrayCategory;
  640.                 }
  641.             }
  642.                        
  643.             foreach ($decodedResponse['company'] as $company) {
  644.                 $insertCompany = $conn->prepare('UPDATE `company` SET cnpj = :cnpj, ie = :ie,`trading_name`= :trading_name,fantasy_name = :fantasy_name, address = :address,plan = :plan,license =  :license,blocked = :blocked, sync = :sync,created_at = :created_at,updated_at =:updated_at,deleted_at = :deleted_at WHERE id = :id');
  645.                
  646.                 $insertCompany->bindValue(':id', $company['id']);
  647.                 $insertCompany->bindValue(':cnpj', $company['cnpj']);
  648.                 $insertCompany->bindValue(':ie', $company['ie']);
  649.                 $insertCompany->bindValue(':trading_name', $company['trading_name']);
  650.                 $insertCompany->bindValue(':fantasy_name', $company['fantasy_name']);
  651.                 $insertCompany->bindValue(':plan', $company['plan']);
  652.                 $insertCompany->bindValue(':license', $company['license']);
  653.                 $insertCompany->bindValue(':address', $company['address']);
  654.                 $insertCompany->bindValue(':blocked', $company['blocked']);
  655.                 $insertCompany->bindValue(':sync', 'yes');
  656.                 $insertCompany->bindValue(':deleted_at', $company['deleted_at']);
  657.                 $insertCompany->bindValue(':created_at', $company['created_at']);
  658.                 $insertCompany->bindValue(':updated_at', $company['updated_at']);
  659.                
  660.                 $insertCompany->execute();
  661.             }
  662.            
  663.             foreach ($decodedResponse['command'] as $command) {
  664.                 if ($command['sync'] == 'never') {
  665.                     $insertCommand = $conn->prepare('INSERT INTO `command` (id_command_off,id_company,total_value,opening_at,closing_at,`number`,active,sync,created_at,updated_at,deleted_at) VALUES (:id,:id_company,:total_value,:opening_at,:closing_at,:numberC,:active,:sync,:created_at,:updated_at,:deleted_at)');
  666.                     $insertCommand->bindValue(':id_company', $command['id_company']);
  667.                     $insertCommand->bindValue(':id', $command['id']);
  668.                     $insertCommand->bindValue(':opening_at', $command['opening_at']);
  669.                     $insertCommand->bindValue(':total_value', $command['total_value']);
  670.                     $insertCommand->bindValue(':closing_at', $command['closing_at']);
  671.                     $insertCommand->bindValue(':numberC', $command['number']);
  672.                     $insertCommand->bindValue(':active', $command['active']);
  673.                     $insertCommand->bindValue(':sync', 'yes');
  674.                     $insertCommand->bindValue(':deleted_at', $command['deleted_at']);
  675.                     $insertCommand->bindValue(':created_at', $command['created_at']);
  676.                     $insertCommand->bindValue(':updated_at', $command['updated_at']);
  677.                    
  678.                     $insertCommand->execute();
  679.                     // $arrayCategory['id_off'] = $conn->lastInsertId();
  680.                     // $arrayCategory['online_id'] = $command['id'];
  681.                     // $objectCommand[] = $arrayCategory;
  682.                 } else {
  683.                     $insertCommand = $conn->prepare('UPDATE `command` SET opening_at = :opening_at,closing_at = :closing_at,total_value = :total_value,`number` = :numberC, active = :active,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_company = :id_company and id_command_off = :id_command_off');
  684.                     $insertCommand->bindValue(':id_company', $command['id_company']);
  685.                     $insertCommand->bindValue(':id_command_off', $command['id']);
  686.                     $insertCommand->bindValue(':opening_at', $command['opening_at']);
  687.                     $insertCommand->bindValue(':total_value', $command['total_value']);
  688.                     $insertCommand->bindValue(':closing_at', $command['closing_at']);
  689.                     $insertCommand->bindValue(':numberC', $command['number']);
  690.                     $insertCommand->bindValue(':active', $command['active']);
  691.                     $insertCommand->bindValue(':sync', 'yes');
  692.                     $insertCommand->bindValue(':deleted_at', $command['deleted_at']);
  693.                     $insertCommand->bindValue(':created_at', $command['created_at']);
  694.                     $insertCommand->bindValue(':updated_at', $command['updated_at']);
  695.                    
  696.                     $insertCommand->execute();
  697.                     // $arrayCategory['id_off'] = $conn->lastInsertId();
  698.                     // $arrayCategory['online_id'] = $command['id'];
  699.                     // $objectCommand[] = $arrayCategory;
  700.                 }
  701.             }
  702.            
  703.             foreach ($decodedResponse['company_user'] as $user) {
  704.                 if ($user['sync'] == 'never') {
  705.                     $insertUser = $conn->prepare('INSERT INTO `company_user` (id_company,id_company_user_off,qr_password,name,photo,user,password,access_level,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_company_user_off,:qr_password,:name,:photo,:user,:password,:access_level,:sync,:created_at,:updated_at,:deleted_at)');
  706.                     $insertUser->bindValue(':id_company', $user['id_company']);
  707.                     $insertUser->bindValue(':id_company_user_off', $user['id']);
  708.                     $insertUser->bindValue(':name', $user['name']);
  709.                     $insertUser->bindValue(':photo', $user['photo']);
  710.                     $insertUser->bindValue(':user', $user['user']);
  711.                     $insertUser->bindValue(':password', $user['password']);
  712.                     $insertUser->bindValue(':qr_password', $user['qr_password']);
  713.                     $insertUser->bindValue(':access_level', $user['access_level']);
  714.                     $insertUser->bindValue(':sync', 'yes');
  715.                     $insertUser->bindValue(':deleted_at', $user['deleted_at']);
  716.                     $insertUser->bindValue(':created_at', $user['created_at']);
  717.                     $insertUser->bindValue(':updated_at', $user['updated_at']);
  718.                    
  719.                     $insertUser->execute();
  720.                     // $arrayUser['id_off'] = $conn->lastInsertId();
  721.                     // $userOnlineId = $user['id'];
  722.                     // $userOffId = $arrayUser['id_off'];
  723.                     // $arrayUser['online_id'] = $user['id'];
  724.                     // $objUser[] = $arrayUser;
  725.                    
  726.                 } else {
  727.                     $insertUser = $conn->prepare('UPDATE `company_user` SET name = :name,qr_password = :qr_password, photo = :photo,user = :user,password = :password,access_level = :access_level,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_company = :id_company and id_company_user_off = :id_company_user_off');
  728.                     $insertUser->bindValue(':id_company', $user['id_company']);
  729.                     $insertUser->bindValue(':id_company_user_off', $user['id']);
  730.                     $insertUser->bindValue(':name', $user['name']);
  731.                     $insertUser->bindValue(':photo', $user['photo']);
  732.                     $insertUser->bindValue(':qr_password', $user['qr_password']);
  733.                     $insertUser->bindValue(':user', $user['user']);
  734.                     $insertUser->bindValue(':password', $user['password']);
  735.                     $insertUser->bindValue(':access_level', $user['access_level']);
  736.                     $insertUser->bindValue(':sync', 'yes');
  737.                     $insertUser->bindValue(':deleted_at', $user['deleted_at']);
  738.                     $insertUser->bindValue(':created_at', $user['created_at']);
  739.                     $insertUser->bindValue(':updated_at', $user['updated_at']);
  740.                    
  741.                     $insertUser->execute();
  742.                     // $arrayUser['id_off'] = $conn->lastInsertId();
  743.                     // $userOnlineId = $user['id'];
  744.                     // $userOffId = $arrayUser['id_off'];
  745.                     // $arrayUser['online_id'] = $user['id'];
  746.                     // $objUser[] = $arrayUser;
  747.                    
  748.                 }
  749.                
  750.                 if (!empty($user['photo'])) {
  751.                     $this->downloadImage($user['photo']);
  752.                 }
  753.             }
  754.            
  755.             foreach ($decodedResponse['company_log'] as $log) {
  756.                 $selectUser = $conn->prepare('SELECT id from company_user where id_company = :id_company and id_company_user_off = :id_company_user_off');
  757.                 $selectUser->bindValue(':id_company', $log['id_company']);
  758.                 $selectUser->bindValue(':id_company_user_off', $log['id_user']);
  759.                
  760.                 $selectUser->execute();
  761.                 $userId = $selectUser->fetch(PDO::FETCH_ASSOC);
  762.                
  763.                 $insertLog = $conn->prepare('INSERT INTO `company_log` (id_company,id_log_off,id_user,page,message,subject,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_log_off,:id_user,:page,:message,:subject,:sync,:created_at,:updated_at,:deleted_at)');
  764.                 $insertLog->bindValue(':id_company', $log['id_company']);
  765.                 $insertLog->bindValue(':id_log_off', $log['id']);
  766.                 $insertLog->bindValue(':id_user', $userId['id']);
  767.                 $insertLog->bindValue(':page', $log['page']);
  768.                 $insertLog->bindValue(':message', $log['message']);
  769.                 $insertLog->bindValue(':subject', $log['subject']);
  770.                 $insertLog->bindValue(':sync', 'yes');
  771.                 $insertLog->bindValue(':deleted_at', $log['deleted_at']);
  772.                 $insertLog->bindValue(':created_at', $log['created_at']);
  773.                 $insertLog->bindValue(':updated_at', $log['updated_at']);
  774.                
  775.                 $insertLog->execute();
  776.                 // $arrayCategory['id_off'] = $conn->lastInsertId();
  777.                 // $arrayCategory['online_id'] = $log['id'];
  778.                 // $objLog[] = $arrayCategory;
  779.             }
  780.            
  781.             foreach ($decodedResponse['menu'] as $menuType) {
  782.                 if ($menuType['sync'] == 'never') {
  783.                     $insertMenuType = $conn->prepare('INSERT INTO `menu_type` (id_company,id_menu_type_off,name,description,status,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_menu_type_off,:name,:description,:status,:sync,:created_at,:updated_at,:deleted_at)');
  784.                     $insertMenuType->bindValue(':id_menu_type_off', $menuType['id']);
  785.                     $insertMenuType->bindValue(':id_company', $menuType['id_company']);
  786.                     $insertMenuType->bindValue(':name', $menuType['name']);
  787.                     $insertMenuType->bindValue(':description', $menuType['description']);
  788.                     $insertMenuType->bindValue(':status', $menuType['status']);
  789.                     $insertMenuType->bindValue(':sync', 'yes');
  790.                     $insertMenuType->bindValue(':deleted_at', $menuType['deleted_at']);
  791.                     $insertMenuType->bindValue(':created_at', $menuType['created_at']);
  792.                     $insertMenuType->bindValue(':updated_at', $menuType['updated_at']);
  793.                    
  794.                     $insertMenuType->execute();
  795.                     // $arrayMenu['id_off'] = $conn->lastInsertId();
  796.                     // $arrayMenu['online_id'] = $menuType['id'];
  797.                     // $objMenu[] = $arrayMenu;
  798.                    
  799.                 } else {
  800.                     $insertMenuType = $conn->prepare('UPDATE `menu_type` SET name = :name,description = :description,status = :status,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_company = :id_company and id_menu_type_off = :id_menu_type_off');
  801.                     $insertMenuType->bindValue(':id_menu_type_off', $menuType['id']);
  802.                     $insertMenuType->bindValue(':id_company', $menuType['id_company']);
  803.                     $insertMenuType->bindValue(':name', $menuType['name']);
  804.                     $insertMenuType->bindValue(':description', $menuType['description']);
  805.                     $insertMenuType->bindValue(':status', $menuType['status']);
  806.                     $insertMenuType->bindValue(':sync', 'yes');
  807.                     $insertMenuType->bindValue(':deleted_at', $menuType['deleted_at']);
  808.                     $insertMenuType->bindValue(':created_at', $menuType['created_at']);
  809.                     $insertMenuType->bindValue(':updated_at', $menuType['updated_at']);
  810.                    
  811.                     $insertMenuType->execute();
  812.                 }
  813.             }
  814.            
  815.             foreach ($decodedResponse['preference'] as $preference) {
  816.                 if ($preference['sync'] == 'never') {
  817.                     $insertPreference = $conn->prepare('INSERT INTO `preference` (id_company,id_preference_off,name,description,display,multiple,`order`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_preference_off,:name,:description,:display,:multiple,:order,:sync,:created_at,:updated_at,:deleted_at)');
  818.                     $insertPreference->bindValue(':id_company', $preference['id_company']);
  819.                     $insertPreference->bindValue(':id_preference_off', $preference['id']);
  820.                     $insertPreference->bindValue(':name', $preference['name']);
  821.                     $insertPreference->bindValue(':description', $preference['description']);
  822.                     $insertPreference->bindValue(':display', $preference['display']);
  823.                     $insertPreference->bindValue(':multiple', $preference['multiple']);
  824.                     $insertPreference->bindValue(':order', $preference['order']);
  825.                     $insertPreference->bindValue(':sync', 'yes');
  826.                     $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
  827.                     $insertPreference->bindValue(':created_at', $preference['created_at']);
  828.                     $insertPreference->bindValue(':updated_at', $preference['updated_at']);
  829.                    
  830.                     $insertPreference->execute();
  831.                     // $preferenceArray['id_off'] = $conn->lastInsertId();
  832.                     // $preferenceId = $preferenceArray['id_off'];
  833.                     // $preferenceArray['online_id'] = $preference['id'];
  834.                     // $preferenceOnlineId = $preference['id'];
  835.                     // $arrayPreferenceOffline[] = $preferenceArray['id_off'];
  836.                     // $arrayPreferenceOnline[] = $preference['id'];
  837.                     // $objPreference[] = $preferenceArray;
  838.                 } else {
  839.                     $insertPreference = $conn->prepare('UPDATE `preference` SET name = :name,description = :description,display = :display,multiple = :multiple,`order` = :order,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_company = :id_company and id_preference_off = :id_preference_off');
  840.                     $insertPreference->bindValue(':id_preference_off', $preference['id']);
  841.                     $insertPreference->bindValue(':id_company', $preference['id_company']);
  842.                     $insertPreference->bindValue(':name', $preference['name']);
  843.                     $insertPreference->bindValue(':description', $preference['description']);
  844.                     $insertPreference->bindValue(':display', $preference['display']);
  845.                     $insertPreference->bindValue(':multiple', $preference['multiple']);
  846.                     $insertPreference->bindValue(':order', $preference['order']);
  847.                     $insertPreference->bindValue(':sync', 'yes');
  848.                     $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
  849.                     $insertPreference->bindValue(':created_at', $preference['created_at']);
  850.                     $insertPreference->bindValue(':updated_at', $preference['updated_at']);
  851.                    
  852.                     $insertPreference->execute();
  853.                 }
  854.                
  855.                 //items de uma preferencia
  856.             }
  857.  
  858.             foreach ($decodedResponse['preference_category'] as $preference) {
  859.                 $selectCategory = $conn->prepare('SELECT id from category where id_company = :id_company and id_category_off = :id_category_off');
  860.                 $selectCategory->bindValue(':id_company', $preference['id_company']);
  861.                 $selectCategory->bindValue(':id_category_off', $preference['id_category']);
  862.                
  863.                 $selectCategory->execute();
  864.                 $categoryId = $selectCategory->fetch(PDO::FETCH_ASSOC);
  865.                
  866.                 $selectPreference = $conn->prepare('SELECT id from preference where id_company = :id_company and id_preference_off = :id_preference_off');
  867.                 $selectPreference->bindValue(':id_company', $preference['id_company']);
  868.                 $selectPreference->bindValue(':id_preference_off', $preference['id_preference']);
  869.                
  870.                 $selectPreference->execute();
  871.                 $preferenceId = $selectPreference->fetch(PDO::FETCH_ASSOC);
  872.                
  873.                 if ($preference['sync'] == 'never') {
  874.                     $insertPreference = $conn->prepare('INSERT INTO `preference_category` (id_company,id_preference_category_off,id_category,id_preference,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_preference_category_off,:id_category,:id_preference,:sync,:created_at,:updated_at,:deleted_at)');
  875.                     $insertPreference->bindValue(':id_company', $preference['id_company']);
  876.                     $insertPreference->bindValue(':id_preference_category_off', $preference['id']);
  877.                     $insertPreference->bindValue(':id_category', $categoryId['id']);
  878.                     $insertPreference->bindValue(':id_preference', $preferenceId['id']);
  879.                     $insertPreference->bindValue(':sync', 'yes');
  880.                     $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
  881.                     $insertPreference->bindValue(':created_at', $preference['created_at']);
  882.                     $insertPreference->bindValue(':updated_at', $preference['updated_at']);
  883.                    
  884.                     $insertPreference->execute();
  885.                     // $preferenceArray['id_off'] = $conn->lastInsertId();
  886.                     // $preferenceArray['online_id'] = $preference['id'];
  887.                     // $objPreferenceCategory[] = $preferenceArray;
  888.                    
  889.                 } else {
  890.                     $insertPreference = $conn->prepare('UPDATE `preference_category` SET id_category = :id_category,id_preference = :id_preference,sync = :sync,created_at = :created_at,updated_at = :updated_at ,deleted_at = :deleted_at WHERE id_company = :id_company and id_preference_category_off = :id_preference_category_off');
  891.                     $insertPreference->bindValue(':id_preference_category_off', $preference['id']);
  892.                     $insertPreference->bindValue(':id_company', $preference['id_company']);
  893.                     $insertPreference->bindValue(':id_category', $categoryId['id']);
  894.                     $insertPreference->bindValue(':id_preference', $preferenceId['id']);
  895.                     $insertPreference->bindValue(':sync', 'yes');
  896.                     $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
  897.                     $insertPreference->bindValue(':created_at', $preference['created_at']);
  898.                     $insertPreference->bindValue(':updated_at', $preference['updated_at']);
  899.                    
  900.                     $insertPreference->execute();
  901.                 }
  902.             }
  903.            
  904.             foreach ($decodedResponse['preference_item'] as $preference) {
  905.                 $selectPreference = $conn->prepare('SELECT id from preference where id_company = :id_company and id_preference_off = :id_preference_off');
  906.                 $selectPreference->bindValue(':id_company', $preference['id_company']);
  907.                 $selectPreference->bindValue(':id_preference_off', $preference['id_preference']);
  908.                
  909.                 $selectPreference->execute();
  910.                 $preferenceId = $selectPreference->fetch(PDO::FETCH_ASSOC);
  911.                
  912.                 if ($preference['sync'] == 'never') {
  913.                     $insertPreference = $conn->prepare('INSERT INTO `preference_item` (id_company,id_preference_item_off,id_preference,name,description,status,`order`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_preference_item_off,:id_preference,:name,:description,:status,:order,:sync,:created_at,:updated_at,:deleted_at)');
  914.                     $insertPreference->bindValue(':id_company', $preference['id_company']);
  915.                     $insertPreference->bindValue(':id_preference', $preferenceId['id']);
  916.                     $insertPreference->bindValue(':id_preference_item_off', $preference['id']);
  917.                     $insertPreference->bindValue(':name', $preference['name']);
  918.                     $insertPreference->bindValue(':description', $preference['description']);
  919.                     $insertPreference->bindValue(':order', $preference['order']);
  920.                     $insertPreference->bindValue(':status', $preference['status']);
  921.                     $insertPreference->bindValue(':sync', 'yes');
  922.                     $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
  923.                     $insertPreference->bindValue(':created_at', $preference['created_at']);
  924.                     $insertPreference->bindValue(':updated_at', $preference['updated_at']);
  925.                    
  926.                     $insertPreference->execute();
  927.                     // $preferenceArray['id_off'] = $conn->lastInsertId();
  928.                     // $preferenceArray['online_id'] = $preference['id'];
  929.                     // $objPreferenceItem[] = $preferenceArray;
  930.                    
  931.                 } else {
  932.                     $insertPreference = $conn->prepare('UPDATE `preference_item` SET id_preference = :id_preference,name = :name,description = :description,status = :status,`order` = :order,sync = :sync,created_at =:created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_preference_item_off = :id_preference_item_off and id_company = :id_company');
  933.                     $insertPreference->bindValue(':id_preference_item_off', $preference['id']);
  934.                     $insertPreference->bindValue(':id_company', $preference['id_company']);
  935.                     $insertPreference->bindValue(':id_preference', $preferenceId['id']);
  936.                     $insertPreference->bindValue(':name', $preference['name']);
  937.                     $insertPreference->bindValue(':description', $preference['description']);
  938.                     $insertPreference->bindValue(':order', $preference['order']);
  939.                     $insertPreference->bindValue(':status', $preference['status']);
  940.                     $insertPreference->bindValue(':sync', 'yes');
  941.                     $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
  942.                     $insertPreference->bindValue(':created_at', $preference['created_at']);
  943.                     $insertPreference->bindValue(':updated_at', $preference['updated_at']);
  944.                    
  945.                     $insertPreference->execute();
  946.                 }
  947.             }
  948.            
  949.             foreach ($decodedResponse['sale_type'] as $sale) {
  950.                 if ($sale['sync'] == 'never') {
  951.                     $saleType = $conn->prepare('INSERT INTO `sale_type` (id_company,id_sale_type_off,name,description,`status`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_sale_type_off,:name,:description,:status,:sync,:created_at,:updated_at,:deleted_at)');
  952.                     $saleType->bindValue(':id_company', $sale['id_company']);
  953.                     $saleType->bindValue(':id_sale_type_off', $sale['id']);
  954.                     $saleType->bindValue(':name', $sale['name']);
  955.                     $saleType->bindValue(':status', $sale['status']);
  956.                     $saleType->bindValue(':description', $sale['description']);
  957.                     $saleType->bindValue(':sync', 'yes');
  958.                     $saleType->bindValue(':deleted_at', $sale['deleted_at']);
  959.                     $saleType->bindValue(':created_at', $sale['created_at']);
  960.                     $saleType->bindValue(':updated_at', $sale['updated_at']);
  961.                    
  962.                     $saleType->execute();
  963.                     // $productArray['id_off'] = $conn->lastInsertId();
  964.                     // $productArray['online_id'] = $sale['id'];
  965.                     // $arraySalesOnline[] = $sale['id'];
  966.                     // $arraySalesOffline[] = $productArray['id_off'];
  967.                     // $objSale[] = $productArray;
  968.                    
  969.                 } else {
  970.                     $saleType = $conn->prepare('UPDATE `sale_type` SET name = :name,description = :description,`status` = :status,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_company = :id_company and id_sale_type_off = :id_sale_type_off');
  971.                     $saleType->bindValue(':id_sale_type_off', $sale['id']);
  972.                     $saleType->bindValue(':id_company', $sale['id_company']);
  973.                     $saleType->bindValue(':name', $sale['name']);
  974.                     $saleType->bindValue(':status', $sale['status']);
  975.                     $saleType->bindValue(':description', $sale['description']);
  976.                     $saleType->bindValue(':sync', 'yes');
  977.                     $saleType->bindValue(':deleted_at', $sale['deleted_at']);
  978.                     $saleType->bindValue(':created_at', $sale['created_at']);
  979.                     $saleType->bindValue(':updated_at', $sale['updated_at']);
  980.                    
  981.                     $saleType->execute();
  982.                 }
  983.             }
  984.            
  985.             foreach ($decodedResponse['products'] as $product) {
  986.                 if ($product['sync'] == 'never') {
  987.                     $insertProduct = $conn->prepare('INSERT INTO `product` (id_company,id_product_off,id_system,name,description,all_you_can_eat,`order`,status,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_product_off,:id_system,:name,:description,:all_you_can_eat,:order,:status,:sync,:created_at,:updated_at,:deleted_at)');
  988.                     $insertProduct->bindValue(':id_company', $product['id_company']);
  989.                     $insertProduct->bindValue(':id_product_off', $product['id']);
  990.                     $insertProduct->bindValue(':name', $product['name']);
  991.                     $insertProduct->bindValue(':description', $product['description']);
  992.                     $insertProduct->bindValue(':order', $product['order']);
  993.                     $insertProduct->bindValue(':status', $product['status']);
  994.                     $insertProduct->bindValue(':id_system', $product['id_system']);
  995.                     $insertProduct->bindValue(':all_you_can_eat', $product['all_you_can_eat']);
  996.                     $insertProduct->bindValue(':sync', 'yes');
  997.                     $insertProduct->bindValue(':deleted_at', $product['deleted_at']);
  998.                     $insertProduct->bindValue(':created_at', $product['created_at']);
  999.                     $insertProduct->bindValue(':updated_at', $product['updated_at']);
  1000.                    
  1001.                     $insertProduct->execute();
  1002.                     // $productArray['id_off'] = $conn->lastInsertId();
  1003.                     // $productId = $productArray['id_off'];
  1004.                     // $productArray['online_id'] = $product['id'];
  1005.                     // $productOnlineId = $product['id'];
  1006.                     // $arrayProductOnline[] = $productOnlineId;
  1007.                     // $arrayProductOff[] = $productId;
  1008.                     // $objProducts[] = $productArray;
  1009.                    
  1010.                 } else {
  1011.                     $insertProduct = $conn->prepare('UPDATE `product` SET id_system = :id_system,name = :name,description = :description,all_you_can_eat = :all_you_can_eat,`order` = :order,status = :status,sync = :sync,created_at =:created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_product_off = :id and id_company = :id_company');
  1012.                     $insertProduct->bindValue(':id', $product['id']);
  1013.                     $insertProduct->bindValue(':id_company', $product['id_company']);
  1014.                     $insertProduct->bindValue(':name', $product['name']);
  1015.                     $insertProduct->bindValue(':description', $product['description']);
  1016.                     $insertProduct->bindValue(':order', $product['order']);
  1017.                     $insertProduct->bindValue(':status', $product['status']);
  1018.                     $insertProduct->bindValue(':id_system', $product['id_system']);
  1019.                     $insertProduct->bindValue(':all_you_can_eat', $product['all_you_can_eat']);
  1020.                     $insertProduct->bindValue(':sync', 'yes');
  1021.                     $insertProduct->bindValue(':deleted_at', $product['deleted_at']);
  1022.                     $insertProduct->bindValue(':created_at', $product['created_at']);
  1023.                     $insertProduct->bindValue(':updated_at', $product['updated_at']);
  1024.                    
  1025.                     $insertProduct->execute();
  1026.                 }
  1027.             }
  1028.            
  1029.             foreach ($decodedResponse['product_additionals'] as $product_additional) {
  1030.                 $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
  1031.                 $selectProduct->bindValue(':id_company', $product_additional['id_company']);
  1032.                 $selectProduct->bindValue(':id_product_off', $product_additional['id_product']);
  1033.                
  1034.                 $selectProduct->execute();
  1035.                 $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1036.                
  1037.                 $selectAdditional = $conn->prepare('SELECT id from additional where id_company = :id_company and id_additional_off = :id_additional_off');
  1038.                 $selectAdditional->bindValue(':id_company', $product_additional['id_company']);
  1039.                 $selectAdditional->bindValue(':id_additional_off', $product_additional['id_additional']);
  1040.                
  1041.                 $selectAdditional->execute();
  1042.                 $additionalId = $selectAdditional->fetch(PDO::FETCH_ASSOC);
  1043.                
  1044.                
  1045.                 if ($product_additional['sync'] == 'never') {
  1046.                     $insertProduct = $conn->prepare('INSERT INTO `product_additional` (id_company,id_product_additional_off,id_product,id_additional,`order`,status,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_product_additional_off,:id_product,:id_additional,:order,:status,:sync,:created_at,:updated_at,:deleted_at)');
  1047.                     $insertProduct->bindValue(':id_company', $product_additional['id_company']);
  1048.                     $insertProduct->bindValue(':id_product_additional_off', $product_additional['id']);
  1049.                     $insertProduct->bindValue(':id_additional', $additionalId['id']);
  1050.                     $insertProduct->bindValue(':id_product', $productId['id']);
  1051.                     $insertProduct->bindValue(':order', $product_additional['order']);
  1052.                     $insertProduct->bindValue(':status', $product_additional['status']);
  1053.                     $insertProduct->bindValue(':sync', 'yes');
  1054.                     $insertProduct->bindValue(':deleted_at', $product_additional['deleted_at']);
  1055.                     $insertProduct->bindValue(':created_at', $product_additional['created_at']);
  1056.                     $insertProduct->bindValue(':updated_at', $product_additional['updated_at']);
  1057.                    
  1058.                     $insertProduct->execute();
  1059.                     // $productAdditionalArray['id_off'] = $conn->lastInsertId();
  1060.                     // $productAdditionalArray['online_id'] = $product_additional['id'];
  1061.                     // $objProductsAdditionals[] = $productAdditionalArray;
  1062.                    
  1063.                 } else {
  1064.                     $insertProduct = $conn->prepare('UPDATE `product_additional` SET id_product = :id_product,id_additional = :id_additional,`order` = :order,status = :status,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_product_additional_off = :id and id_company = :id_company');
  1065.                     $insertProduct->bindValue(':id', $product_additional['id']);
  1066.                     $insertProduct->bindValue(':id_company', $product_additional['id_company']);
  1067.                     $insertProduct->bindValue(':id_additional', $additionalId['id']);
  1068.                     $insertProduct->bindValue(':id_product', $productId['id']);
  1069.                     $insertProduct->bindValue(':order', $product_additional['order']);
  1070.                     $insertProduct->bindValue(':status', $product_additional['status']);
  1071.                     $insertProduct->bindValue(':sync', 'yes');
  1072.                     $insertProduct->bindValue(':deleted_at', $product_additional['deleted_at']);
  1073.                     $insertProduct->bindValue(':created_at', $product_additional['created_at']);
  1074.                     $insertProduct->bindValue(':updated_at', $product_additional['updated_at']);
  1075.                    
  1076.                     $insertProduct->execute();
  1077.                 }
  1078.             }
  1079.            
  1080.             foreach ($decodedResponse['product_category'] as $product) {
  1081.                 $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
  1082.                 $selectProduct->bindValue(':id_company', $product['id_company']);
  1083.                 $selectProduct->bindValue(':id_product_off', $product['id_product']);
  1084.                
  1085.                 $selectProduct->execute();
  1086.                 $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1087.                
  1088.                 $selectCategory = $conn->prepare('SELECT id from category where id_company = :id_company and id_category_off = :id_category_off');
  1089.                 $selectCategory->bindValue(':id_company', $product['id_company']);
  1090.                 $selectCategory->bindValue(':id_category_off', $product['id_category']);
  1091.                
  1092.                 $selectCategory->execute();
  1093.                 $categoryId = $selectCategory->fetch(PDO::FETCH_ASSOC);
  1094.                
  1095.                 if ($product['sync'] == 'never') {
  1096.                     $insertProduct = $conn->prepare('INSERT INTO `product_category` (id_company,id_product_category_off,id_category,id_product,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_product_category_off,:id_category,:id_product,:sync,:created_at,:updated_at,:deleted_at)');
  1097.                     $insertProduct->bindValue(':id_product_category_off', $product['id']);
  1098.                     $insertProduct->bindValue(':id_company', $product['id_company']);
  1099.                     $insertProduct->bindValue(':id_category', $categoryId['id']);
  1100.                     $insertProduct->bindValue(':id_product', $productId['id']);
  1101.                     $insertProduct->bindValue(':sync', 'yes');
  1102.                     $insertProduct->bindValue(':deleted_at', $product['deleted_at']);
  1103.                     $insertProduct->bindValue(':created_at', $product['created_at']);
  1104.                     $insertProduct->bindValue(':updated_at', $product['updated_at']);
  1105.                    
  1106.                     $insertProduct->execute();
  1107.                     // $productArray['id_off'] = $conn->lastInsertId();
  1108.                     // $productArray['online_id'] = $product['id'];
  1109.                     // $objProductsCategory[] = $productArray;
  1110.                    
  1111.                 } else {
  1112.                     $insertProduct = $conn->prepare('UPDATE `product_category` SET id_category = :id_category,id_product = :id_product,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at where id_product_category_off = :id and id_company = :id_company');
  1113.                     $insertProduct->bindValue(':id', $product['id']);
  1114.                     $insertProduct->bindValue(':id_company', $product['id_company']);
  1115.                     $insertProduct->bindValue(':id_category', $categoryId['id']);
  1116.                     $insertProduct->bindValue(':id_product', $productId['id']);
  1117.                     $insertProduct->bindValue(':sync', 'yes');
  1118.                     $insertProduct->bindValue(':deleted_at', $product['deleted_at']);
  1119.                     $insertProduct->bindValue(':created_at', $product['created_at']);
  1120.                     $insertProduct->bindValue(':updated_at', $product['updated_at']);
  1121.                    
  1122.                     $insertProduct->execute();
  1123.                 }
  1124.             }
  1125.            
  1126.             foreach ($decodedResponse['product_exibition'] as $product_exibition) {
  1127.                 $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
  1128.                 $selectProduct->bindValue(':id_company', $product_exibition['id_company']);
  1129.                 $selectProduct->bindValue(':id_product_off', $product_exibition['id_product']);
  1130.                
  1131.                
  1132.                 $selectProduct->execute();
  1133.                 $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1134.                
  1135.                 if ($product_exibition['sync'] == 'never') {
  1136.                     $insertProductExibition = $conn->prepare('INSERT INTO `product_exibition` (id_company,id_product_exibition_off,id_product,day,`at`,`to`,`display`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_product_exibition_off,:id_product,:day,:at,:to,:display,:sync,:created_at,:updated_at,:deleted_at)');
  1137.                     $insertProductExibition->bindValue(':id_company', $product_exibition['id_company']);
  1138.                     $insertProductExibition->bindValue(':id_product', $productId['id']);
  1139.                     $insertProductExibition->bindValue(':id_product_exibition_off', $product_exibition['id']);
  1140.                     $insertProductExibition->bindValue(':day', $product_exibition['day']);
  1141.                     $insertProductExibition->bindValue(':at', $product_exibition['at']);
  1142.                     $insertProductExibition->bindValue(':to', $product_exibition['to']);
  1143.                     $insertProductExibition->bindValue(':display', $product_exibition['display']);
  1144.                     $insertProductExibition->bindValue(':sync', 'yes');
  1145.                     $insertProductExibition->bindValue(':deleted_at', $product_exibition['deleted_at']);
  1146.                     $insertProductExibition->bindValue(':created_at', $product_exibition['created_at']);
  1147.                     $insertProductExibition->bindValue(':updated_at', $product_exibition['updated_at']);
  1148.                    
  1149.                     $insertProductExibition->execute();
  1150.                     // $productArray['id_off'] = $conn->lastInsertId();
  1151.                     // $productArray['online_id'] = $product_exibition['id'];
  1152.                     // $objProductsExibition[] = $productArray;
  1153.                    
  1154.                 } else {
  1155.                     $insertProductExibition = $conn->prepare('UPDATE `product_exibition` SET id_product = :id_product,day = :day,`at` = :at,`to` = :to,`display` = :display,sync = :sync,created_at = :created_at,updated_at =:updated_at,deleted_at = :deleted_at WHERE id_product_exibition_off = :id and id_company = :id_company');
  1156.                     $insertProductExibition->bindValue(':id', $product_exibition['id']);
  1157.                     $insertProductExibition->bindValue(':id_company', $product_exibition['id_company']);
  1158.                     $insertProductExibition->bindValue(':id_product', $productId['id']);
  1159.                     $insertProductExibition->bindValue(':day', $product_exibition['day']);
  1160.                     $insertProductExibition->bindValue(':at', $product_exibition['at']);
  1161.                     $insertProductExibition->bindValue(':to', $product_exibition['to']);
  1162.                     $insertProductExibition->bindValue(':display', $product_exibition['display']);
  1163.                     $insertProductExibition->bindValue(':sync', 'yes');
  1164.                     $insertProductExibition->bindValue(':deleted_at', $product_exibition['deleted_at']);
  1165.                     $insertProductExibition->bindValue(':created_at', $product_exibition['created_at']);
  1166.                     $insertProductExibition->bindValue(':updated_at', $product_exibition['updated_at']);
  1167.                    
  1168.                     $insertProductExibition->execute();
  1169.                 }
  1170.             }
  1171.            
  1172.             foreach ($decodedResponse['product_image'] as $product_exibition) {
  1173.                 $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
  1174.                 $selectProduct->bindValue(':id_company', $product_exibition['id_company']);
  1175.                 $selectProduct->bindValue(':id_product_off', $product_exibition['id_product']);
  1176.                
  1177.                 $selectProduct->execute();
  1178.                 $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1179.                
  1180.                 if ($product_exibition['sync'] == 'never') {
  1181.                     $insertProductImage = $conn->prepare('INSERT INTO `product_image` (id_company,id_product_image_off,id_product,`order`,image,`status`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_product_image_off,:id_product,:order,:image,:status,:sync,:created_at,:updated_at,:deleted_at)');
  1182.                     $insertProductImage->bindValue(':id_company', $product_exibition['id_company']);
  1183.                     $insertProductImage->bindValue(':id_product_image_off', $product_exibition['id']);
  1184.                     $insertProductImage->bindValue(':id_product', $productId['id']);
  1185.                     $insertProductImage->bindValue(':order', $product_exibition['order']);
  1186.                     $insertProductImage->bindValue(':image', $product_exibition['image']);
  1187.                     $insertProductImage->bindValue(':status', $product_exibition['status']);
  1188.                     $insertProductImage->bindValue(':sync', 'yes');
  1189.                     $insertProductImage->bindValue(':deleted_at', $product_exibition['deleted_at']);
  1190.                     $insertProductImage->bindValue(':created_at', $product_exibition['created_at']);
  1191.                     $insertProductImage->bindValue(':updated_at', $product_exibition['updated_at']);
  1192.                    
  1193.                     $insertProductImage->execute();
  1194.                     // $productArray['id_off'] = $conn->lastInsertId();
  1195.                     // $productArray['online_id'] = $product_exibition['id'];
  1196.                     // $objProductImage[] = $productArray;
  1197.                    
  1198.                 } else {
  1199.                     $insertProductImage = $conn->prepare('UPDATE `product_image` SET id_product = :id_product,`order` = :order,image = :image,`status` = :status,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_product_image_off = :id and id_company = :id_company');
  1200.                     $insertProductImage->bindValue(':id', $product_exibition['id']);
  1201.                     $insertProductImage->bindValue(':id_company', $product_exibition['id_company']);
  1202.                     $insertProductImage->bindValue(':id_product', $productId['id']);
  1203.                     $insertProductImage->bindValue(':order', $product_exibition['order']);
  1204.                     $insertProductImage->bindValue(':image', $product_exibition['image']);
  1205.                     $insertProductImage->bindValue(':status', $product_exibition['status']);
  1206.                     $insertProductImage->bindValue(':sync', 'yes');
  1207.                     $insertProductImage->bindValue(':deleted_at', $product_exibition['deleted_at']);
  1208.                     $insertProductImage->bindValue(':created_at', $product_exibition['created_at']);
  1209.                     $insertProductImage->bindValue(':updated_at', $product_exibition['updated_at']);
  1210.                    
  1211.                     $insertProductImage->execute();
  1212.                 }
  1213.                
  1214.                 if (!empty($product_exibition['image'])) {
  1215.                     $this->downloadImage($product_exibition['image']);
  1216.                 }
  1217.             }
  1218.            
  1219.             foreach ($decodedResponse['product_preference'] as $product) {
  1220.                 $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
  1221.                 $selectProduct->bindValue(':id_company', $product['id_company']);
  1222.                 $selectProduct->bindValue(':id_product_off', $product['id_product']);
  1223.                
  1224.                 $selectProduct->execute();
  1225.                 $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1226.                
  1227.                 $selectPreference = $conn->prepare('SELECT id from preference where id_company = :id_company and id_preference_off = :id_preference_off');
  1228.                 $selectPreference->bindValue(':id_company', $product['id_company']);
  1229.                 $selectPreference->bindValue(':id_preference_off', $product['id_preference']);
  1230.                
  1231.                
  1232.                 $selectPreference->execute();
  1233.                 $preferenceId = $selectPreference->fetch(PDO::FETCH_ASSOC);
  1234.                
  1235.                 if ($product['sync'] == 'never') {
  1236.                     $productPreference = $conn->prepare('INSERT INTO `product_preference` (id_company,id_product_preference_off,id_product,id_preference,`status`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_product_preference_off,:id_product,:id_preference,:status,:sync,:created_at,:updated_at,:deleted_at)');
  1237.                     $productPreference->bindValue(':id_company', $product['id_company']);
  1238.                     $productPreference->bindValue(':id_product_preference_off', $product['id']);
  1239.                     $productPreference->bindValue(':id_product', $productId['id']);
  1240.                     $productPreference->bindValue(':id_preference', $preferenceId['id']);
  1241.                     $productPreference->bindValue(':status', $product['status']);
  1242.                     $productPreference->bindValue(':sync', 'yes');
  1243.                     $productPreference->bindValue(':deleted_at', $product['deleted_at']);
  1244.                     $productPreference->bindValue(':created_at', $product['created_at']);
  1245.                     $productPreference->bindValue(':updated_at', $product['updated_at']);
  1246.                    
  1247.                     $productPreference->execute();
  1248.                     // $productArray['id_off'] = $conn->lastInsertId();
  1249.                     // $productArray['online_id'] = $product['id'];
  1250.                     // $objProductPreference[] = $productArray;
  1251.                    
  1252.                 } else {
  1253.                     $productPreference = $conn->prepare('UPDATE `product_preference` SET id_product = :id_product,id_preference = :id_preference,`status` = :status,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_product_preference_off = :id and id_company = :id_company');
  1254.                     $productPreference->bindValue(':id', $product['id']);
  1255.                     $productPreference->bindValue(':id_company', $product['id_company']);
  1256.                     $productPreference->bindValue(':id_product', $productId['id']);
  1257.                     $productPreference->bindValue(':id_preference', $preferenceId['id']);
  1258.                     $productPreference->bindValue(':status', $product['status']);
  1259.                     $productPreference->bindValue(':sync', 'yes');
  1260.                     $productPreference->bindValue(':deleted_at', $product['deleted_at']);
  1261.                     $productPreference->bindValue(':created_at', $product['created_at']);
  1262.                     $productPreference->bindValue(':updated_at', $product['updated_at']);
  1263.                    
  1264.                     $productPreference->execute();
  1265.                 }
  1266.             }
  1267.            
  1268.             foreach ($decodedResponse['product_types'] as $product) {
  1269.                 $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
  1270.                 $selectProduct->bindValue(':id_company', $product['id_company']);
  1271.                 $selectProduct->bindValue(':id_product_off', $product['id_product']);
  1272.                
  1273.                 $selectProduct->execute();
  1274.                 $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1275.                
  1276.                 if ($product['sync'] == 'never') {
  1277.                     $productPreference = $conn->prepare('INSERT INTO `product_type` (id_company,id_product_type_off,id_product,name,description,`price`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_product_type_off,:id_product,:name,:description,:price,:sync,:created_at,:updated_at,:deleted_at)');
  1278.                     $productPreference->bindValue(':id_company', $product['id_company']);
  1279.                     $productPreference->bindValue(':id_product_type_off', $product['id']);
  1280.                     $productPreference->bindValue(':id_product', $productId['id']);
  1281.                     $productPreference->bindValue(':name', $product['name']);
  1282.                     $productPreference->bindValue(':price', $product['price']);
  1283.                     $productPreference->bindValue(':description', $product['description']);
  1284.                     $productPreference->bindValue(':sync', 'yes');
  1285.                     $productPreference->bindValue(':deleted_at', $product['deleted_at']);
  1286.                     $productPreference->bindValue(':created_at', $product['created_at']);
  1287.                     $productPreference->bindValue(':updated_at', $product['updated_at']);
  1288.                    
  1289.                     $productPreference->execute();
  1290.                     // $productArray['id_off'] = $conn->lastInsertId();
  1291.                     // $productArray['online_id'] = $product['id'];
  1292.                     // $objProductTypes[] = $productArray;
  1293.                    
  1294.                 } else {
  1295.                     $productPreference = $conn->prepare('UPDATE `product_type` SET id_product = :id_product,name = :name,description = :description,`price` = :price,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_product_type_off = :id and id_company = :id_company ');
  1296.                     $productPreference->bindValue(':id', $product['id']);
  1297.                     $productPreference->bindValue(':id_company', $product['id_company']);
  1298.                     $productPreference->bindValue(':id_product', $productId['id']);
  1299.                     $productPreference->bindValue(':name', $product['name']);
  1300.                     $productPreference->bindValue(':price', $product['price']);
  1301.                     $productPreference->bindValue(':description', $product['description']);
  1302.                     $productPreference->bindValue(':sync', 'yes');
  1303.                     $productPreference->bindValue(':deleted_at', $product['deleted_at']);
  1304.                     $productPreference->bindValue(':created_at', $product['created_at']);
  1305.                     $productPreference->bindValue(':updated_at', $product['updated_at']);
  1306.                    
  1307.                     $productPreference->execute();
  1308.                 }
  1309.             }
  1310.            
  1311.             foreach ($decodedResponse['product_sales'] as $product) {
  1312.                 $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
  1313.                 $selectProduct->bindValue(':id_company', $product['id_company']);
  1314.                 $selectProduct->bindValue(':id_product_off', $product['id_product']);
  1315.                
  1316.                 $selectProduct->execute();
  1317.                 $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1318.                
  1319.                 $selectSale = $conn->prepare('SELECT id from sale_type where id_company = :id_company and id_sale_type_off = :id_sale_type_off');
  1320.                 $selectSale->bindValue(':id_company', $product['id_company']);
  1321.                 $selectSale->bindValue(':id_sale_type_off', $product['id_sale_type']);
  1322.                
  1323.                
  1324.                 $selectSale->execute();
  1325.                 $saleId = $selectSale->fetch(PDO::FETCH_ASSOC);
  1326.                
  1327.                 if ($product['sync'] == 'never') {
  1328.                     $productPreference = $conn->prepare('INSERT INTO `product_sale` (id_company,id_product_sale_off,id_product,id_sale_type,`status`,quantity,day,month,year,`at`,`to`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_product_sale_off,:id_product,:id_sale_type,:status,:quantity,:day,:month,:year,:at,:to,:sync,:created_at,:updated_at,:deleted_at)');
  1329.                     $productPreference->bindValue(':id_company', $product['id_company']);
  1330.                     $productPreference->bindValue(':id_product_sale_off', $product['id']);
  1331.                     $productPreference->bindValue(':id_product', $productId['id']);
  1332.                     $productPreference->bindValue(':id_sale_type', $saleId['id']);
  1333.                     $productPreference->bindValue(':quantity', $product['quantity']);
  1334.                     $productPreference->bindValue(':day', $product['day']);
  1335.                     $productPreference->bindValue(':month', $product['month']);
  1336.                     $productPreference->bindValue(':year', $product['year']);
  1337.                     $productPreference->bindValue(':at', $product['at']);
  1338.                     $productPreference->bindValue(':to', $product['to']);
  1339.                     $productPreference->bindValue(':status', $product['status']);
  1340.                     $productPreference->bindValue(':sync', 'yes');
  1341.                     $productPreference->bindValue(':deleted_at', $product['deleted_at']);
  1342.                     $productPreference->bindValue(':created_at', $product['created_at']);
  1343.                     $productPreference->bindValue(':updated_at', $product['updated_at']);
  1344.                    
  1345.                     $productPreference->execute();
  1346.                     // $productArray['id_off'] = $conn->lastInsertId();
  1347.                     // $productArray['online_id'] = $product['id'];
  1348.                     // $objProductSale[] = $productArray;
  1349.                    
  1350.                 } else {
  1351.                     $productPreference = $conn->prepare('UPDATE `product_sale` SET id_product = :id_product,id_sale_type = :id_sale_type,`status` = :status,quantity = :quantity,day = :day,month = :month,year = :year,`at` = :at,`to` = :to,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at where id_product_sale_off = :id and id_company = :id_company');
  1352.                     $productPreference->bindValue(':id', $product['id']);
  1353.                     $productPreference->bindValue(':id_company', $product['id_company']);
  1354.                     $productPreference->bindValue(':id_product', $productId['id']);
  1355.                     $productPreference->bindValue(':id_sale_type', $saleId['id']);
  1356.                     $productPreference->bindValue(':quantity', $product['quantity']);
  1357.                     $productPreference->bindValue(':day', $product['day']);
  1358.                     $productPreference->bindValue(':month', $product['month']);
  1359.                     $productPreference->bindValue(':year', $product['year']);
  1360.                     $productPreference->bindValue(':at', $product['at']);
  1361.                     $productPreference->bindValue(':to', $product['to']);
  1362.                     $productPreference->bindValue(':status', $product['status']);
  1363.                     $productPreference->bindValue(':sync', 'yes');
  1364.                     $productPreference->bindValue(':deleted_at', $product['deleted_at']);
  1365.                     $productPreference->bindValue(':created_at', $product['created_at']);
  1366.                     $productPreference->bindValue(':updated_at', $product['updated_at']);
  1367.                    
  1368.                     $productPreference->execute();
  1369.                 }
  1370.             }
  1371.            
  1372.             foreach ($decodedResponse['product_tags'] as $product) {
  1373.                 $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
  1374.                 $selectProduct->bindValue(':id_company', $product['id_company']);
  1375.                 $selectProduct->bindValue(':id_product_off', $product['id_product']);
  1376.                
  1377.                 $selectProduct->execute();
  1378.                 $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1379.                
  1380.                 if ($product['sync'] == 'never') {
  1381.                     $productPreference = $conn->prepare('INSERT INTO `product_tag` (id_company,id_product_tag_off,id_product,id_tag,display,`status`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_product_tag_off,:id_product,:id_tag,:display,:status,:sync,:created_at,:updated_at,:deleted_at)');
  1382.                     $productPreference->bindValue(':id_company', $product['id_company']);
  1383.                     $productPreference->bindValue(':id_product_tag_off', $product['id']);
  1384.                     $productPreference->bindValue(':id_product', $productId['id']);
  1385.                     $productPreference->bindValue(':id_tag', $product['id_tag']);
  1386.                     $productPreference->bindValue(':status', $product['status']);
  1387.                     $productPreference->bindValue(':display', $product['display']);
  1388.                     $productPreference->bindValue(':sync', 'yes');
  1389.                     $productPreference->bindValue(':deleted_at', $product['deleted_at']);
  1390.                     $productPreference->bindValue(':created_at', $product['created_at']);
  1391.                     $productPreference->bindValue(':updated_at', $product['updated_at']);
  1392.                    
  1393.                     $productPreference->execute();
  1394.                     $productArray['id_off']    = $conn->lastInsertId();
  1395.                     $productArray['online_id'] = $product['id'];
  1396.                     $objProductTag[]           = $productArray;
  1397.                    
  1398.                 } else {
  1399.                     $productPreference = $conn->prepare('UPDATE `product_tag` SET id_product = :id_product,id_tag = :id_tag,display = :display,`status` = :status,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_product_tag_off = :id and id_company = :id_company');
  1400.                     $productPreference->bindValue(':id', $product['id']);
  1401.                     $productPreference->bindValue(':id_company', $product['id_company']);
  1402.                     $productPreference->bindValue(':id_product', $productId['id']);
  1403.                     $productPreference->bindValue(':id_tag', $product['id_tag']);
  1404.                     $productPreference->bindValue(':status', $product['status']);
  1405.                     $productPreference->bindValue(':display', $product['display']);
  1406.                     $productPreference->bindValue(':sync', 'yes');
  1407.                     $productPreference->bindValue(':deleted_at', $product['deleted_at']);
  1408.                     $productPreference->bindValue(':created_at', $product['created_at']);
  1409.                     $productPreference->bindValue(':updated_at', $product['updated_at']);
  1410.                    
  1411.                     $productPreference->execute();
  1412.                 }
  1413.             }
  1414.            
  1415.             foreach ($decodedResponse['table'] as $table) {
  1416.                 $selectWaiter = $conn->prepare('SELECT id from company_user where id_company = :id_company and id_company_user_off = :id_waiter');
  1417.                 $selectWaiter->bindValue(':id_company', $table['id_company']);
  1418.                 $selectWaiter->bindValue(':id_waiter', $table['id_waiter']);
  1419.                
  1420.                 $selectWaiter->execute();
  1421.                 $waiterId = $selectWaiter->fetch(PDO::FETCH_ASSOC);
  1422.                
  1423.                 if ($table['sync'] == 'never') {
  1424.                     $insertTable = $conn->prepare('INSERT INTO `table` (id_company,id_table_off,id_waiter,`number`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_table_off,:id_waiter,:num,:sync,:created_at,:updated_at,:deleted_at)');
  1425.                     $insertTable->bindValue(':id_company', $table['id_company']);
  1426.                     $insertTable->bindValue(':id_table_off', $table['id']);
  1427.                     $insertTable->bindValue(':id_waiter', $waiterId['id']);
  1428.                     $insertTable->bindValue(':num', $table['number']);
  1429.                     $insertTable->bindValue(':sync', 'yes');
  1430.                     $insertTable->bindValue(':deleted_at', $table['deleted_at']);
  1431.                     $insertTable->bindValue(':created_at', $table['created_at']);
  1432.                     $insertTable->bindValue(':updated_at', $table['updated_at']);
  1433.                    
  1434.                     $insertTable->execute();
  1435.                     // $productArray['id_off'] = $conn->lastInsertId();
  1436.                     // $productArray['online_id'] = $table['id'];
  1437.                     // $objTable[] = $productArray;
  1438.                    
  1439.                 } else {
  1440.                     $insertTable = $conn->prepare('UPDATE `table` SET id_waiter = :id_waiter,`number` = :num,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_table_off = :id and id_company = :id_company');
  1441.                     $insertTable->bindValue(':id', $table['id']);
  1442.                     $insertTable->bindValue(':id_company', $table['id_company']);
  1443.                     $insertTable->bindValue(':id_waiter', $waiterId['id']);
  1444.                     $insertTable->bindValue(':num', $table['number']);
  1445.                     $insertTable->bindValue(':sync', 'yes');
  1446.                     $insertTable->bindValue(':deleted_at', $table['deleted_at']);
  1447.                     $insertTable->bindValue(':created_at', $table['created_at']);
  1448.                     $insertTable->bindValue(':updated_at', $table['updated_at']);
  1449.                    
  1450.                     $insertTable->execute();
  1451.                 }
  1452.             }
  1453.            
  1454.             foreach ($decodedResponse['command_table'] as $command_table) {
  1455.                 $selectProduct = $conn->prepare('SELECT id from `table` where id_company = :id_company and id_table_off = :id_table_off');
  1456.                 $selectProduct->bindValue(':id_company', $command_table['id_company']);
  1457.                 $selectProduct->bindValue(':id_table_off', $command_table['id_table']);
  1458.                
  1459.                 $selectProduct->execute();
  1460.                 $tableId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1461.                
  1462.                 $selectProduct = $conn->prepare('SELECT id from command where id_company = :id_company and id_command_off = :id_command_off');
  1463.                 $selectProduct->bindValue(':id_company', $command_table['id_company']);
  1464.                 $selectProduct->bindValue(':id_command_off', $command_table['id_command']);
  1465.                
  1466.                 $selectProduct->execute();
  1467.                 $commandId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1468.                
  1469.                 if ($command_table['sync'] == 'never') {
  1470.                     $insertCommandTable = $conn->prepare('INSERT INTO `command_table` (id_command_table_off,id_company,id_table,id_command,sync,created_at,updated_at,deleted_at) VALUES (:id_command_table_off,:id_company,:id_table,:id_command,:sync,:created_at,:updated_at,:deleted_at)');
  1471.                     $insertCommandTable->bindValue(':id_command_table_off', $command_table['id']);
  1472.                     $insertCommandTable->bindValue(':id_company', $command_table['id_company']);
  1473.                     $insertCommandTable->bindValue(':id_table', $tableId['id']);
  1474.                     $insertCommandTable->bindValue(':id_command', $commandId['id']);
  1475.                     $insertCommandTable->bindValue(':sync', 'yes');
  1476.                     $insertCommandTable->bindValue(':deleted_at', $command_table['deleted_at']);
  1477.                     $insertCommandTable->bindValue(':created_at', $command_table['created_at']);
  1478.                     $insertCommandTable->bindValue(':updated_at', $command_table['updated_at']);
  1479.                    
  1480.                     $insertCommandTable->execute();
  1481.                     // $productArray['id_off'] = $conn->lastInsertId();
  1482.                     // $productArray['online_id'] = $command_table['id'];
  1483.                     // $objCommandTable[] = $productArray;
  1484.                    
  1485.                 } else {
  1486.                     $insertCommandTable = $conn->prepare('UPDATE `command_table` SET id_table = :id_table,id_command = :id_command,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_command_table_off = :id and id_company = :id_company');
  1487.                     $insertCommandTable->bindValue(':id', $command_table['id']);
  1488.                     $insertCommandTable->bindValue(':id_company', $command_table['id_company']);
  1489.                     $insertCommandTable->bindValue(':id_table', $tableId['id']);
  1490.                     $insertCommandTable->bindValue(':id_command', $commandId['id']);
  1491.                     $insertCommandTable->bindValue(':sync', 'yes');
  1492.                     $insertCommandTable->bindValue(':deleted_at', $command_table['deleted_at']);
  1493.                     $insertCommandTable->bindValue(':created_at', $command_table['created_at']);
  1494.                     $insertCommandTable->bindValue(':updated_at', $command_table['updated_at']);
  1495.                    
  1496.                     $insertCommandTable->execute();
  1497.                 }
  1498.             }
  1499.            
  1500.             foreach ($decodedResponse['combo'] as $combo) {
  1501.                 if ($combo['sync'] == 'never') {
  1502.                     $insertCombo = $conn->prepare('INSERT INTO `combo` (id_company,id_combo_off,name,description,price,active,all_you_can_eat,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_combo_off,:name,:description,:price,:active,:all_you_can_eat,:sync,:created_at,:updated_at,:deleted_at)');
  1503.                     $insertCombo->bindValue(':id_company', $combo['id_company']);
  1504.                     $insertCombo->bindValue(':id_combo_off', $combo['id']);
  1505.                     $insertCombo->bindValue(':price', $combo['price']);
  1506.                     $insertCombo->bindValue(':active', $combo['active']);
  1507.                     $insertCombo->bindValue(':all_you_can_eat', $combo['all_you_can_eat']);
  1508.                     $insertCombo->bindValue(':name', $combo['name']);
  1509.                     $insertCombo->bindValue(':description', $combo['description']);
  1510.                     $insertCombo->bindValue(':sync', 'yes');
  1511.                     $insertCombo->bindValue(':deleted_at', $combo['deleted_at']);
  1512.                     $insertCombo->bindValue(':created_at', $combo['created_at']);
  1513.                     $insertCombo->bindValue(':updated_at', $combo['updated_at']);
  1514.                    
  1515.                     $insertCombo->execute();
  1516.                     // $productArray['id_off'] = $conn->lastInsertId();
  1517.                     // $productArray['online_id'] = $combo['id'];
  1518.                     // $comboOnlineId = $combo['id'];
  1519.                     // $comboOfflineId = $productArray['id_off'];
  1520.                     // $objCombo[] = $productArray;
  1521.                    
  1522.                 } else {
  1523.                     $insertCombo = $conn->prepare('UPDATE `combo` SET id_company = :id_company,name = :name,description = :description,price = :price,active = :active,all_you_can_eat = :all_you_can_eat,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_combo_off = :id');
  1524.                     $insertCombo->bindValue(':id', $combo['id']);
  1525.                     $insertCombo->bindValue(':id_company', $combo['id_company']);
  1526.                     $insertCombo->bindValue(':price', $combo['price']);
  1527.                     $insertCombo->bindValue(':active', $combo['active']);
  1528.                     $insertCombo->bindValue(':all_you_can_eat', $combo['all_you_can_eat']);
  1529.                     $insertCombo->bindValue(':name', $combo['name']);
  1530.                     $insertCombo->bindValue(':description', $combo['description']);
  1531.                     $insertCombo->bindValue(':sync', 'yes');
  1532.                     $insertCombo->bindValue(':deleted_at', $combo['deleted_at']);
  1533.                     $insertCombo->bindValue(':created_at', $combo['created_at']);
  1534.                     $insertCombo->bindValue(':updated_at', $combo['updated_at']);
  1535.                    
  1536.                     $insertCombo->execute();
  1537.                 }
  1538.             }
  1539.            
  1540.             foreach ($decodedResponse['combo_group'] as $combo_group) {
  1541.                 $selectCombo = $conn->prepare('SELECT id from combo where id_company = :id_company and id_combo_off = :id_combo_off');
  1542.                 $selectCombo->bindValue(':id_company', $combo_group['company_id']);
  1543.                 $selectCombo->bindValue(':id_combo_off', $combo_group['combo_id']);
  1544.                
  1545.                 $selectCombo->execute();
  1546.                 $comboId = $selectCombo->fetch(PDO::FETCH_ASSOC);
  1547.                
  1548.                 if ($combo_group['sync'] == 'never') {
  1549.                     $insertComboGroup = $conn->prepare('INSERT INTO `combo_group` (company_id,id_combo_group_off,name,combo_id,sync,created_at,updated_at,deleted_at) VALUES (:company_id,:id_combo_group_off,:name,:combo_id,:sync,:created_at,:updated_at,:deleted_at)');
  1550.                     $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
  1551.                     $insertComboGroup->bindValue(':id_combo_group_off', $combo_group['id']);
  1552.                     $insertComboGroup->bindValue(':name', $combo_group['name']);
  1553.                     $insertComboGroup->bindValue(':combo_id', $comboId['id']);
  1554.                     $insertComboGroup->bindValue(':sync', 'yes');
  1555.                     $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
  1556.                     $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
  1557.                     $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
  1558.                    
  1559.                     $insertComboGroup->execute();
  1560.                     // $productArray['id_off'] = $conn->lastInsertId();
  1561.                     // $productArray['online_id'] = $combo_group['id'];
  1562.                     // $comboGroupOnlineId = $combo_group['id'];
  1563.                     // $comboGroupOffId = $productArray['id_off'];
  1564.                     // $objComboGroup[] = $productArray;
  1565.                    
  1566.                 } else {
  1567.                     $insertComboGroup = $conn->prepare('UPDATE `combo_group` SET name = :name,combo_id = :combo_id,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at where id_combo_group_off = :id and company_id = :company_id');
  1568.                     $insertComboGroup->bindValue(':id', $combo_group['id']);
  1569.                     $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
  1570.                     $insertComboGroup->bindValue(':name', $combo_group['name']);
  1571.                     $insertComboGroup->bindValue(':combo_id', $comboId['id']);
  1572.                     $insertComboGroup->bindValue(':sync', 'yes');
  1573.                     $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
  1574.                     $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
  1575.                     $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
  1576.                    
  1577.                     $insertComboGroup->execute();
  1578.                 }
  1579.             }
  1580.            
  1581.             foreach ($decodedResponse['combo_group_item'] as $combo_group) {
  1582.                 $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
  1583.                 $selectProduct->bindValue(':id_company', $combo_group['company_id']);
  1584.                 $selectProduct->bindValue(':id_product_off', $combo_group['product_id']);
  1585.                
  1586.                 $selectProduct->execute();
  1587.                 $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1588.                
  1589.                 $selectCombo = $conn->prepare('SELECT id from combo_group where company_id = :id_company and id_combo_group_off = :id_combo_group_off');
  1590.                 $selectCombo->bindValue(':id_company', $combo_group['company_id']);
  1591.                 $selectCombo->bindValue(':id_combo_group_off', $combo_group['combo_group_id']);
  1592.                
  1593.                
  1594.                 $selectCombo->execute();
  1595.                 $comboGroupId = $selectCombo->fetch(PDO::FETCH_ASSOC);
  1596.                
  1597.                 if ($combo_group['sync'] == 'never') {
  1598.                     $insertComboGroup = $conn->prepare('INSERT INTO `combo_group_item` (company_id,id_combo_group_item_off,product_id,combo_group_id,`order`,additional_price,sync,created_at,updated_at,deleted_at) VALUES (:company_id,:id_combo_group_item_off,:product_id,:combo_group_id,:order,:additional_price,:sync,:created_at,:updated_at,:deleted_at)');
  1599.                     $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
  1600.                     $insertComboGroup->bindValue(':id_combo_group_item_off', $combo_group['id']);
  1601.                     $insertComboGroup->bindValue(':product_id', $productId['id']);
  1602.                     $insertComboGroup->bindValue(':combo_group_id', $comboGroupId['id']);
  1603.                     $insertComboGroup->bindValue(':order', $combo_group['order']);
  1604.                     $insertComboGroup->bindValue(':additional_price', $combo_group['additional_price']);
  1605.                     $insertComboGroup->bindValue(':sync', 'yes');
  1606.                     $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
  1607.                     $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
  1608.                     $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
  1609.                    
  1610.                     $insertComboGroup->execute();
  1611.                     // $productArray['id_off'] = $conn->lastInsertId();
  1612.                     // $productArray['online_id'] = $combo_group['id'];
  1613.                     // $objComboGroupItem[] = $productArray;
  1614.                    
  1615.                 } else {
  1616.                     $insertComboGroup = $conn->prepare('UPDATE `combo_group_item` SET product_id = :product_id,combo_group_id = :combo_group_id,`order` = :order,additional_price = :additional_price,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_combo_group_item_off = :id and company_id = :company_id');
  1617.                     $insertComboGroup->bindValue(':id', $combo_group['id']);
  1618.                     $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
  1619.                     $insertComboGroup->bindValue(':product_id', $productId['id']);
  1620.                     $insertComboGroup->bindValue(':combo_group_id', $comboGroupId['id']);
  1621.                     $insertComboGroup->bindValue(':order', $combo_group['order']);
  1622.                     $insertComboGroup->bindValue(':additional_price', $combo_group['additional_price']);
  1623.                     $insertComboGroup->bindValue(':sync', 'yes');
  1624.                     $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
  1625.                     $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
  1626.                     $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
  1627.                    
  1628.                     $insertComboGroup->execute();
  1629.                 }
  1630.             }
  1631.            
  1632.             foreach ($decodedResponse['combo_exibition'] as $combo_group) {
  1633.                 $selectCombo = $conn->prepare('SELECT id from combo where id_company = :id_company and id_combo_off = :id_combo_off');
  1634.                 $selectCombo->bindValue(':id_company', $combo_group['company_id']);
  1635.                 $selectCombo->bindValue(':id_combo_off', $combo_group['combo_id']);
  1636.                
  1637.                 $selectCombo->execute();
  1638.                 $comboId = $selectCombo->fetch(PDO::FETCH_ASSOC);
  1639.                
  1640.                 if ($combo_group['sync'] == 'never') {
  1641.                     $insertComboGroup = $conn->prepare('INSERT INTO `combo_exibition` (company_id,id_combo_exibition_off,`at`,combo_id,`to`,display,day,sync,created_at,updated_at,deleted_at) VALUES (:company_id,:id_combo_exibition_off,:at,:combo_id,:to,:display,:day,:sync,:created_at,:updated_at,:deleted_at)');
  1642.                     $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
  1643.                     $insertComboGroup->bindValue(':id_combo_exibition_off', $combo_group['id']);
  1644.                     $insertComboGroup->bindValue(':at', $combo_group['at']);
  1645.                     $insertComboGroup->bindValue(':to', $combo_group['to']);
  1646.                     $insertComboGroup->bindValue(':combo_id', $comboId['id']);
  1647.                     $insertComboGroup->bindValue(':display', $combo_group['display']);
  1648.                     $insertComboGroup->bindValue(':day', $combo_group['day']);
  1649.                     $insertComboGroup->bindValue(':sync', 'yes');
  1650.                     $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
  1651.                     $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
  1652.                     $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
  1653.                    
  1654.                     $insertComboGroup->execute();
  1655.                     // $productArray['id_off'] = $conn->lastInsertId();
  1656.                     // $productArray['online_id'] = $combo_group['id'];
  1657.                     // $objComboExibition[] = $productArray;
  1658.                    
  1659.                 } else {
  1660.                     $insertComboGroup = $conn->prepare('UPDATE `combo_exibition` SET `at` = :at,combo_id = :combo_id,`to` = :to,display = :display,day = :day,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_combo_exibition_off = :id and company_id = :company_id');
  1661.                     $insertComboGroup->bindValue(':id', $combo_group['id']);
  1662.                     $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
  1663.                     $insertComboGroup->bindValue(':at', $combo_group['at']);
  1664.                     $insertComboGroup->bindValue(':to', $combo_group['to']);
  1665.                     $insertComboGroup->bindValue(':combo_id', $comboId['id']);
  1666.                     $insertComboGroup->bindValue(':display', $combo_group['display']);
  1667.                     $insertComboGroup->bindValue(':day', $combo_group['day']);
  1668.                     $insertComboGroup->bindValue(':sync', 'yes');
  1669.                     $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
  1670.                     $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
  1671.                     $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
  1672.                    
  1673.                     $insertComboGroup->execute();
  1674.                 }
  1675.             }
  1676.            
  1677.             foreach ($decodedResponse['combo_type'] as $combo_group) {
  1678.                 $selectCombo = $conn->prepare('SELECT id from combo where id_company = :id_company and id_combo_off = :id_combo_off');
  1679.                 $selectCombo->bindValue(':id_company', $combo_group['company_id']);
  1680.                 $selectCombo->bindValue(':id_combo_off', $combo_group['combo_id']);
  1681.                
  1682.                 $selectCombo->execute();
  1683.                 $comboId = $selectCombo->fetch(PDO::FETCH_ASSOC);
  1684.                
  1685.                 if ($combo_group['sync'] == 'never') {
  1686.                     $insertComboGroup = $conn->prepare('INSERT INTO `combo_type` (company_id,id_combo_type_off,name,combo_id,description,price,sync,created_at,updated_at,deleted_at) VALUES (:company_id,:id_combo_type_off,:name,:combo_id,:description,:price,:sync,:created_at,:updated_at,:deleted_at)');
  1687.                     $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
  1688.                     $insertComboGroup->bindValue(':id_combo_type_off', $combo_group['id']);
  1689.                     $insertComboGroup->bindValue(':name', $combo_group['name']);
  1690.                     $insertComboGroup->bindValue(':combo_id', $comboId['id']);
  1691.                     $insertComboGroup->bindValue(':description', $combo_group['description']);
  1692.                     $insertComboGroup->bindValue(':price', $combo_group['price']);
  1693.                     $insertComboGroup->bindValue(':sync', 'yes');
  1694.                     $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
  1695.                     $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
  1696.                     $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
  1697.                    
  1698.                     $insertComboGroup->execute();
  1699.                     // $productArray['id_off'] = $conn->lastInsertId();
  1700.                     // $productArray['online_id'] = $combo_group['id'];
  1701.                     // $objComboType[] = $productArray;
  1702.                    
  1703.                 } else {
  1704.                     $insertComboGroup = $conn->prepare('UPDATE `combo_type` SET name = :name,combo_id = :combo_id,description = :description,price = :price,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_combo_type_off = :id and company_id = :company_id');
  1705.                     $insertComboGroup->bindValue(':id', $combo_group['id']);
  1706.                     $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
  1707.                     $insertComboGroup->bindValue(':name', $combo_group['name']);
  1708.                     $insertComboGroup->bindValue(':combo_id', $comboId['id']);
  1709.                     $insertComboGroup->bindValue(':description', $combo_group['description']);
  1710.                     $insertComboGroup->bindValue(':price', $combo_group['price']);
  1711.                     $insertComboGroup->bindValue(':sync', 'yes');
  1712.                     $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
  1713.                     $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
  1714.                     $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
  1715.                    
  1716.                     $insertComboGroup->execute();
  1717.                 }
  1718.             }
  1719.            
  1720.             foreach ($decodedResponse['combo_image'] as $combo_group) {
  1721.                 $selectCombo = $conn->prepare('SELECT id from combo where id_company = :id_company and id_combo_off = :id_combo_off');
  1722.                 $selectCombo->bindValue(':id_company', $combo_group['id_company']);
  1723.                 $selectCombo->bindValue(':id_combo_off', $combo_group['id_combo']);
  1724.                
  1725.                 $selectCombo->execute();
  1726.                 $comboId = $selectCombo->fetch(PDO::FETCH_ASSOC);
  1727.                
  1728.                 if ($combo_group['sync'] == 'never') {
  1729.                     $insertComboGroup = $conn->prepare('INSERT INTO `combo_image` (id_company,id_combo_image_off,image,id_combo,`order`,sync,created_at,updated_at,deleted_at) VALUES (:id_company,:id_combo_image_off,:image,:id_combo,:order,:sync,:created_at,:updated_at,:deleted_at)');
  1730.                     $insertComboGroup->bindValue(':id_company', $combo_group['id_company']);
  1731.                     $insertComboGroup->bindValue(':id_combo_image_off', $combo_group['id']);
  1732.                     $insertComboGroup->bindValue(':image', $combo_group['image']);
  1733.                     $insertComboGroup->bindValue(':id_combo', $comboId['id']);
  1734.                     $insertComboGroup->bindValue(':order', $combo_group['order']);
  1735.                     $insertComboGroup->bindValue(':sync', 'yes');
  1736.                     $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
  1737.                     $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
  1738.                     $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
  1739.                    
  1740.                     $insertComboGroup->execute();
  1741.                     // $productArray['id_off'] = $conn->lastInsertId();
  1742.                     // $productArray['online_id'] = $combo_group['id'];
  1743.                     // $objComboType[] = $productArray;
  1744.                    
  1745.                 } else {
  1746.                     $insertComboGroup = $conn->prepare('UPDATE `combo_image` SET image = :image,id_combo = :id_combo,`order` = :order,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_combo_image_off = :id and id_company = :id_company');
  1747.                     $insertComboGroup->bindValue(':id', $combo_group['id']);
  1748.                     $insertComboGroup->bindValue(':id_company', $combo_group['id_company']);
  1749.                     $insertComboGroup->bindValue(':image', $combo_group['image']);
  1750.                     $insertComboGroup->bindValue(':id_combo', $comboId['id']);
  1751.                     $insertComboGroup->bindValue(':order', $combo_group['order']);
  1752.                     $insertComboGroup->bindValue(':sync', 'yes');
  1753.                     $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
  1754.                     $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
  1755.                     $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
  1756.                    
  1757.                     $insertComboGroup->execute();
  1758.                 }
  1759.                
  1760.                 if (!empty($combo_group['image'])) {
  1761.                     $this->downloadImage($combo_group['image']);
  1762.                 }
  1763.             }
  1764.            
  1765.             foreach ($decodedResponse['restaurant_campaign'] as $campaign) {
  1766.                
  1767.                 if ($campaign['sync'] == 'never') {
  1768.                     $insertCampaign = $conn->prepare('INSERT INTO `restaurant_campaign` (name,id_restaurant_campaign_off,campaign_type,`id_company`,click_counter,`url`,image,`order`,active,sync,created_at,updated_at,deleted_at) VALUES (:name,:id_restaurant_campaign_off,:campaign_type,:id_company,:click_counter,:url,:image,:order,:active,:sync,:created_at,:updated_at,:deleted_at)');
  1769.                     $insertCampaign->bindValue(':id_company', $campaign['id_company']);
  1770.                     $insertCampaign->bindValue(':id_restaurant_campaign_off', $campaign['id']);
  1771.                     $insertCampaign->bindValue(':click_counter', $campaign['click_counter']);
  1772.                     $insertCampaign->bindValue(':name', $campaign['name']);
  1773.                     $insertCampaign->bindValue(':active', $campaign['active']);
  1774.                     $insertCampaign->bindValue(':campaign_type', $campaign['campaign_type']);
  1775.                     $insertCampaign->bindValue(':image', $campaign['image']);
  1776.                     $insertCampaign->bindValue(':order', $campaign['order']);
  1777.                     $insertCampaign->bindValue(':url', $campaign['url']);
  1778.                     $insertCampaign->bindValue(':sync', 'yes');
  1779.                     $insertCampaign->bindValue(':deleted_at', $campaign['deleted_at']);
  1780.                     $insertCampaign->bindValue(':created_at', $campaign['created_at']);
  1781.                     $insertCampaign->bindValue(':updated_at', $campaign['updated_at']);
  1782.                    
  1783.                     $insertCampaign->execute();
  1784.                     // $productArray['id_off'] = $conn->lastInsertId();
  1785.                     // $productArray['online_id'] = $campaign['id'];
  1786.                     // $RestaurantOnline = $campaign['id'];
  1787.                     // $RestaurantOffId = $productArray['id_off'];
  1788.                     // $objRestaurantCampaign[] = $productArray;
  1789.                    
  1790.                 } else {
  1791.                     $insertCampaign = $conn->prepare('UPDATE `restaurant_campaign` SET name = :name,`campaign_type` = :campaign_type,active = :active,`image` = :image,click_counter = :click_counter ,url = :url,`order` = :order, sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_restaurant_campaign_off = :id and id_company = :id_company');
  1792.                     $insertCampaign->bindValue(':id', $campaign['id']);
  1793.                     $insertCampaign->bindValue(':id_company', $campaign['id_company']);
  1794.                     $insertCampaign->bindValue(':click_counter', $campaign['click_counter']);
  1795.                     $insertCampaign->bindValue(':name', $campaign['name']);
  1796.                     $insertCampaign->bindValue(':campaign_type', $campaign['campaign_type']);
  1797.                     $insertCampaign->bindValue(':image', $campaign['image']);
  1798.                     $insertCampaign->bindValue(':active', $campaign['active']);
  1799.                     $insertCampaign->bindValue(':order', $campaign['order']);
  1800.                     $insertCampaign->bindValue(':url', $campaign['url']);
  1801.                     $insertCampaign->bindValue(':sync', 'yes');
  1802.                     $insertCampaign->bindValue(':deleted_at', $campaign['deleted_at']);
  1803.                     $insertCampaign->bindValue(':created_at', $campaign['created_at']);
  1804.                     $insertCampaign->bindValue(':updated_at', $campaign['updated_at']);
  1805.                    
  1806.                     $insertCampaign->execute();
  1807.                 }
  1808.                
  1809.                 if (!empty($campaign['image'])) {
  1810.                     $this->downloadImage($campaign['image']);
  1811.                 }
  1812.             }
  1813.            
  1814.             foreach ($decodedResponse['restaurant_campaign_product'] as $campaign) {
  1815.                
  1816.                 $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
  1817.                 $selectProduct->bindValue(':id_company', $campaign['id_company']);
  1818.                 $selectProduct->bindValue(':id_product_off', $campaign['id_product']);
  1819.                
  1820.                 $selectProduct->execute();
  1821.                 $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  1822.                
  1823.                 $selectCampaign = $conn->prepare('SELECT id from restaurant_campaign where id_company = :id_company and id_restaurant_campaign_off = :id_restaurant_campaign_off');
  1824.                 $selectCampaign->bindValue(':id_company', $campaign['id_company']);
  1825.                 $selectCampaign->bindValue(':id_restaurant_campaign_off', $campaign['id_campaign']);
  1826.                
  1827.                 $selectCampaign->execute();
  1828.                 $campaignId = $selectCampaign->fetch(PDO::FETCH_ASSOC);
  1829.                
  1830.                 if ($campaign['sync'] == 'never') {
  1831.                     $insertCampaign = $conn->prepare('INSERT INTO `restaurant_campaign_product` (id_restaurant_campaign_product_off,id_campaign,`id_company`,id_product,sync,created_at,updated_at,deleted_at) VALUES (:id_restaurant_campaign_product_off,:id_campaign,:id_company,:id_product,:sync,:created_at,:updated_at,:deleted_at)');
  1832.                     $insertCampaign->bindValue(':id_company', $campaign['id_company']);
  1833.                     $insertCampaign->bindValue(':id_restaurant_campaign_product_off', $campaign['id']);
  1834.                     $insertCampaign->bindValue(':id_product', $productId['id']);
  1835.                     $insertCampaign->bindValue(':id_campaign', $campaignId['id']);
  1836.                     $insertCampaign->bindValue(':sync', 'yes');
  1837.                     $insertCampaign->bindValue(':deleted_at', $campaign['deleted_at']);
  1838.                     $insertCampaign->bindValue(':created_at', $campaign['created_at']);
  1839.                     $insertCampaign->bindValue(':updated_at', $campaign['updated_at']);
  1840.                    
  1841.                     $insertCampaign->execute();
  1842.                     // $productArray['id_off'] = $conn->lastInsertId();
  1843.                     // $productArray['online_id'] = $campaign['id'];
  1844.                     // $objRestaurantCampaignProduct[] = $productArray;
  1845.                    
  1846.                 } else {
  1847.                     $insertCampaign = $conn->prepare('UPDATE `restaurant_campaign_product` SET `id_campaign` = :id_campaign,id_product = :id_product, sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_restaurant_campaign_product_off = :id and id_company = :id_company');
  1848.                     $insertCampaign->bindValue(':id', $campaign['id']);
  1849.                     $insertCampaign->bindValue(':id_company', $campaign['id_company']);
  1850.                     $insertCampaign->bindValue(':id_product', $productId['id']);
  1851.                     $insertCampaign->bindValue(':id_campaign', $campaignId['id']);
  1852.                     $insertCampaign->bindValue(':sync', 'yes');
  1853.                     $insertCampaign->bindValue(':deleted_at', $campaign['deleted_at']);
  1854.                     $insertCampaign->bindValue(':created_at', $campaign['created_at']);
  1855.                     $insertCampaign->bindValue(':updated_at', $campaign['updated_at']);
  1856.                    
  1857.                     $insertCampaign->execute();
  1858.                 }
  1859.             }
  1860.  
  1861.             foreach ($decodedResponse['order'] as $order) {
  1862.                 //seleciona a mesa
  1863.                 $selectTable = $conn->prepare('SELECT id from `table` where id_company = :id_company and id_table_off = :id_table');
  1864.                 $selectTable->bindValue(':id_company', $order['id_company']);
  1865.                 $selectTable->bindValue(':id_table', $order['id_table']);
  1866.                
  1867.                 $selectTable->execute();
  1868.                 $tableId = $selectTable->fetch(PDO::FETCH_ASSOC);
  1869.                
  1870.                 //seleciona a comanda
  1871.                 $selectCommand = $conn->prepare('SELECT id from command where id_company = :id_company and id_command_off = :id_command');
  1872.                 $selectCommand->bindValue(':id_company', $order['id_company']);
  1873.                 $selectCommand->bindValue(':id_command', $order['id_command']);
  1874.                
  1875.                 $selectCommand->execute();
  1876.                 $commandId = $selectCommand->fetch(PDO::FETCH_ASSOC);
  1877.                
  1878.                 if ($order['sync'] == 'never') {
  1879.                     $orderInsert = $conn->prepare('INSERT INTO `order` (id_order_off,id_company,id_table,id_command,status,use_service,sync,created_at,updated_at,deleted_at) VALUES (:id,:id_company,:id_table,:id_command,:status,:use_service,:sync,:created_at,:updated_at,:deleted_at)');
  1880.                     $orderInsert->bindValue(':id_table', $tableId['id']);
  1881.                     $orderInsert->bindValue(':id_company', $order['id_company']);
  1882.                     $orderInsert->bindValue(':id_command', $commandId['id']);
  1883.                     $orderInsert->bindValue(':id', $order['id']);
  1884.                     $orderInsert->bindValue(':status', $order['status']);
  1885.                     $orderInsert->bindValue(':use_service', $order['use_service']);
  1886.                     $orderInsert->bindValue(':sync', 'yes');
  1887.                     $orderInsert->bindValue(':created_at', $order['created_at']);
  1888.                     $orderInsert->bindValue(':updated_at', $order['updated_at']);
  1889.                     $orderInsert->bindValue(':deleted_at', $order['deleted_at']);
  1890.                    
  1891.                     $orderInsert->execute();
  1892.                 } else {
  1893.                     $orderInsert = $conn->prepare('UPDATE `order` SET id_table = :id_table,id_command = :id_command,status = :status,use_service = :use_service,sync =:sync,created_at = :created_at,updated_at = :updated_at,deleted_at =:deleted_at WHERE id_order_off = :id and id_company = :id_company');
  1894.                     $orderInsert->bindValue(':id_table', $tableId['id']);
  1895.                     $orderInsert->bindValue(':id_company', $order['id_company']);
  1896.                     $orderInsert->bindValue(':id_command', $commandId['id']);
  1897.                     $orderInsert->bindValue(':id', $order['id']);
  1898.                     $orderInsert->bindValue(':status', $order['status']);
  1899.                     $orderInsert->bindValue(':use_service', $order['use_service']);
  1900.                     $orderInsert->bindValue(':sync', 'yes');
  1901.                     $orderInsert->bindValue(':created_at', $order['created_at']);
  1902.                     $orderInsert->bindValue(':updated_at', $order['updated_at']);
  1903.                     $orderInsert->bindValue(':deleted_at', $order['deleted_at']);
  1904.                    
  1905.                     $orderInsert->execute();
  1906.                 }
  1907.             }
  1908.            
  1909.             foreach ($decodedResponse['order_command'] as $command) {
  1910.                 //seleciona a mesa
  1911.                 $selectTable = $conn->prepare('SELECT id from `table` where id_company = :id_company and id_table_off = :id_table');
  1912.                 $selectTable->bindValue(':id_company', $order['id_company']);
  1913.                 $selectTable->bindValue(':id_table', $order['id_table']);
  1914.                
  1915.                 $selectTable->execute();
  1916.                 $tableId = $selectTable->fetch(PDO::FETCH_ASSOC);
  1917.                
  1918.                 //seleciona a comanda
  1919.                 $selectCommand = $conn->prepare('SELECT id from command where id_company = :id_company and id_command_off = :id_command');
  1920.                 $selectCommand->bindValue(':id_company', $order['id_company']);
  1921.                 $selectCommand->bindValue(':id_command', $order['id_command']);
  1922.                
  1923.                 $selectCommand->execute();
  1924.                 $commandId = $selectCommand->fetch(PDO::FETCH_ASSOC);
  1925.                
  1926.                 //seleciona o pedido
  1927.                 $selectOrder = $conn->prepare('SELECT id from `order` where id_company = :id_company and id_order_off = :id_order');
  1928.                 $selectOrder->bindValue(':id_company', $command['id_company']);
  1929.                 $selectOrder->bindValue(':id_order', $command['id_order']);
  1930.                
  1931.                 $selectOrder->execute();
  1932.                 $orderId = $selectOrder->fetch(PDO::FETCH_ASSOC);
  1933.                
  1934.                 if ($command['sync'] == 'never') {
  1935.                     $orderCommand = $conn->prepare('INSERT INTO `order_command` (id_order_command_off,id_company,id_table,id_command,id_order,sync,created_at,updated_at,deleted_at) VALUES (:id,:id_company,:id_table,:id_command,:id_order,:sync,:created_at,:updated_at,:deleted_at)');
  1936.                     $orderCommand->bindValue(':id_table', $tableId['id']);
  1937.                     $orderCommand->bindValue(':id_company', $command['id_company']);
  1938.                     $orderCommand->bindValue(':id_command', $commandId['id']);
  1939.                     $orderCommand->bindValue(':id_order', $orderId['id']);
  1940.                     $orderCommand->bindValue(':id', $command['id']);
  1941.                     $orderCommand->bindValue(':sync', 'yes');
  1942.                     $orderCommand->bindValue(':created_at', $command['created_at']);
  1943.                     $orderCommand->bindValue(':updated_at', $command['updated_at']);
  1944.                     $orderCommand->bindValue(':deleted_at', $command['deleted_at']);
  1945.                    
  1946.                     $orderCommand->execute();
  1947.                 } else {
  1948.                     $orderCommand = $conn->prepare('UPDATE `order_command` SET id_table = :id_table,id_command = :id_command,id_order = :id_order,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_company = :id_company and id_order_command_off = :id');
  1949.                     $orderCommand->bindValue(':id_table', $tableId['id']);
  1950.                     $orderCommand->bindValue(':id_company', $command['id_company']);
  1951.                     $orderCommand->bindValue(':id_command', $commandId['id']);
  1952.                     $orderCommand->bindValue(':id_order', $orderId['id']);
  1953.                     $orderCommand->bindValue(':id', $command['id']);
  1954.                     $orderCommand->bindValue(':sync', 'yes');
  1955.                     $orderCommand->bindValue(':created_at', $command['created_at']);
  1956.                     $orderCommand->bindValue(':updated_at', $command['updated_at']);
  1957.                     $orderCommand->bindValue(':deleted_at', $command['deleted_at']);
  1958.                    
  1959.                     $orderCommand->execute();
  1960.                 }
  1961.             }
  1962.            
  1963.             foreach ($decodedResponse['order_items'] as $item) {
  1964.                 //seleciona o pedido
  1965.                 $selectOrder = $conn->prepare('SELECT id from `order` where id_company = :id_company and id_order_off = :id_order');
  1966.                 $selectOrder->bindValue(':id_company', $item['id_company']);
  1967.                 $selectOrder->bindValue(':id_order', $item['id_order']);
  1968.                
  1969.                 $selectOrder->execute();
  1970.                 $orderId = $selectOrder->fetch(PDO::FETCH_ASSOC);
  1971.                
  1972.                 //seleciona o menu
  1973.                 $selectMenu = $conn->prepare('SELECT id from menu_type where id_company = :id_company and id_menu_type_off = :id');
  1974.                 $selectMenu->bindValue(':id_company', $item['id_company']);
  1975.                 $selectMenu->bindValue(':id', $item['id']);
  1976.                
  1977.                 $selectMenu->execute();
  1978.                 $menuId = $selectMenu->fetch(PDO::FETCH_ASSOC);
  1979.                
  1980.                 if ($item['is_combo'] == 'yes') {
  1981.                     //seleciona o combo
  1982.                     $selectCombo = $conn->prepare('SELECT id from combo where id_company = :id_company and id_combo_off = :id_combo');
  1983.                     $selectCombo->bindValue(':id_company', $item['id_company']);
  1984.                     $selectCombo->bindValue(':id_combo', $item['id_combo']);
  1985.                    
  1986.                     $selectCombo->execute();
  1987.                     $comboId = $selectCombo->fetch(PDO::FETCH_ASSOC);
  1988.                    
  1989.                     //seleciona o tipo do combo
  1990.                     $selectComboType = $conn->prepare('SELECT id from combo_type where company_id = :id_company and id_combo_type_off = :id_combo_type');
  1991.                     $selectComboType->bindValue(':id_company', $item['id_company']);
  1992.                     $selectComboType->bindValue(':id_combo_type', $item['id_combo_type']);
  1993.                    
  1994.                     $selectComboType->execute();
  1995.                     $comboTypeId = $selectComboType->fetch(PDO::FETCH_ASSOC);
  1996.                    
  1997.                 } else {
  1998.                     //seleciona o produto
  1999.                     $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product');
  2000.                     $selectProduct->bindValue(':id_company', $item['id_company']);
  2001.                     $selectProduct->bindValue(':id_product', $item['id_product']);
  2002.                    
  2003.                     $selectProduct->execute();
  2004.                     $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
  2005.                    
  2006.                     //seleciona o tipo do produto
  2007.                     $selectProductType = $conn->prepare('SELECT id from product_type where id_company = :id_company and id_product_type_off = :id_product_type');
  2008.                     $selectProductType->bindValue(':id_company', $item['id_company']);
  2009.                     $selectProductType->bindValue(':id_product_type', $item['id_product_type']);
  2010.                    
  2011.                     $selectProductType->execute();
  2012.                     $productTypeId = $selectProductType->fetch(PDO::FETCH_ASSOC);
  2013.                 }
  2014.                
  2015.                 if ($item['sync'] == 'never') {
  2016.                     $orderItemInsert = $conn->prepare('INSERT INTO `order_item` (id_order_item_off,id_company,id_order,id_product,id_product_type,id_combo,id_combo_type,id_menu_type,obs,price,quantity,is_combo,sync,created_at,updated_at,deleted_at) VALUES (:id,:id_company,:id_order,:id_product,:id_product_type,:id_combo,:id_combo_type,:id_menu_type,:obs,:price,:quantity,:is_combo,:sync,:created_at,:updated_at,:deleted_at)');
  2017.                     $orderItemInsert->bindValue(':id_order', $orderId['id']);
  2018.                     $orderItemInsert->bindValue(':id', $item['id']);
  2019.                     $orderItemInsert->bindValue(':id_company', $item['id_company']);
  2020.                    
  2021.                     if ($item['is_combo'] == 'yes') {
  2022.                         $orderItemInsert->bindValue(':id_combo', $comboId['id']);
  2023.                         $orderItemInsert->bindValue(':id_combo_type', $comboTypeId['id']);
  2024.                         $orderItemInsert->bindValue(':id_product_type', null);
  2025.                         $orderItemInsert->bindValue(':id_product', null);
  2026.                     } else {
  2027.                         $orderItemInsert->bindValue(':id_product', $productId['id']);
  2028.                         $orderItemInsert->bindValue(':id_combo', null);
  2029.                         $orderItemInsert->bindValue(':id_combo_type', null);
  2030.                         $orderItemInsert->bindValue(':id_product_type', $productTypeId['id']);
  2031.                        
  2032.                     }
  2033.                     $orderItemInsert->bindValue(':id_menu_type', $menuId['id']);
  2034.                     $orderItemInsert->bindValue(':obs', $item['obs']);
  2035.                     $orderItemInsert->bindValue(':price', $item['price']);
  2036.                     $orderItemInsert->bindValue(':quantity', $item['quantity']);
  2037.                     $orderItemInsert->bindValue(':is_combo', $item['is_combo']);
  2038.                     $orderItemInsert->bindValue(':sync', 'yes');
  2039.                     $orderItemInsert->bindValue(':created_at', $item['created_at']);
  2040.                     $orderItemInsert->bindValue(':updated_at', $item['updated_at']);
  2041.                     $orderItemInsert->bindValue(':deleted_at', $item['deleted_at']);
  2042.                    
  2043.                     $orderItemInsert->execute();
  2044.                     $orderItemId = $conn->lastInsertId();
  2045.                 } else {
  2046.                     $orderItemInsert = $conn->prepare('UPDATE `order_item` SET id_order = :id_order,id_product = :id_product,id_product_type = :id_product_type,id_combo = :id_combo,id_combo_type = :id_combo_type,id_menu_type = :id_menu_type,obs = :obs,price = :price,quantity = :quantity,is_combo = :is_combo,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_company = :id_company AND
  2047.                        id_order_item_off = :id');
  2048.                     $orderItemInsert->bindValue(':id_order', $orderId['id']);
  2049.                     $orderItemInsert->bindValue(':id', $item['id']);
  2050.                     $orderItemInsert->bindValue(':id_company', $item['id_company']);
  2051.                     if ($item['is_combo'] == 'yes') {
  2052.                         $orderItemInsert->bindValue(':id_combo', $comboId['id']);
  2053.                         $orderItemInsert->bindValue(':id_combo_type', $comboTypeId['id']);
  2054.                         $orderItemInsert->bindValue(':id_product_type', null);
  2055.                         $orderItemInsert->bindValue(':id_product', null);
  2056.                     } else {
  2057.                         $orderItemInsert->bindValue(':id_product', $productId['id']);
  2058.                         $orderItemInsert->bindValue(':id_combo', null);
  2059.                         $orderItemInsert->bindValue(':id_combo_type', null);
  2060.                         $orderItemInsert->bindValue(':id_product_type', $productTypeId['id']);
  2061.                        
  2062.                     }
  2063.                     $orderItemInsert->bindValue(':id_menu_type', $menuId['id']);
  2064.                     $orderItemInsert->bindValue(':obs', $item['obs']);
  2065.                     $orderItemInsert->bindValue(':price', $item['price']);
  2066.                     $orderItemInsert->bindValue(':quantity', $item['quantity']);
  2067.                     $orderItemInsert->bindValue(':is_combo', $item['is_combo']);
  2068.                     $orderItemInsert->bindValue(':sync', 'yes');
  2069.                     $orderItemInsert->bindValue(':created_at', $item['created_at']);
  2070.                     $orderItemInsert->bindValue(':updated_at', $item['updated_at']);
  2071.                     $orderItemInsert->bindValue(':deleted_at', $item['deleted_at']);
  2072.                    
  2073.                     $orderItemInsert->execute();
  2074.                 }
  2075.             }
  2076.            
  2077.             foreach ($decodedResponse['additional_items'] as $itemAdditional) {
  2078.                 //seleciona o item do pedido
  2079.                 $selectOrderItem = $conn->prepare('SELECT id from order_item where id_company = :id_company and id_order_item_off = :id_order_item');
  2080.                 $selectOrderItem->bindValue(':id_company', $itemAdditional['id_company']);
  2081.                 $selectOrderItem->bindValue(':id_order_item', $itemAdditional['id_order_item']);
  2082.                
  2083.                 $selectOrderItem->execute();
  2084.                 $orderItemId = $selectOrderItem->fetch(PDO::FETCH_ASSOC);
  2085.                
  2086.                 //seleciona o adicional
  2087.                 $selectAdditional = $conn->prepare('SELECT id from additional where id_company = :id_company and id_additional_off = :id_additional');
  2088.                 $selectAdditional->bindValue(':id_company', $itemAdditional['id_company']);
  2089.                 $selectAdditional->bindValue(':id_additional', $itemAdditional['id_additional']);
  2090.                
  2091.                 $selectAdditional->execute();
  2092.                 $additionalId = $selectAdditional->fetch(PDO::FETCH_ASSOC);
  2093.                
  2094.                 if ($item['sync'] == 'never') {
  2095.                     $orderAdditional = $conn->prepare('INSERT INTO `order_item_additional` (id_order_item_additional_off,id_company,id_order_item,id_additional,sync,created_at,updated_at,deleted_at) VALUES (:id,:id_company,:id_order_item,:id_additional,:sync,:created_at,:updated_at,:deleted_at)');
  2096.                     $orderAdditional->bindValue(':id_order_item', $orderItemId['id']);
  2097.                     $orderAdditional->bindValue(':id', $itemAdditional['id']);
  2098.                     $orderAdditional->bindValue(':id_additional', $additionalId['id']);
  2099.                     $orderAdditional->bindValue(':id_company', $itemAdditional['id_company']);
  2100.                     $orderAdditional->bindValue(':sync', 'yes');
  2101.                     $orderAdditional->bindValue(':created_at', $itemAdditional['created_at']);
  2102.                     $orderAdditional->bindValue(':updated_at', $itemAdditional['updated_at']);
  2103.                     $orderAdditional->bindValue(':deleted_at', $itemAdditional['deleted_at']);
  2104.                    
  2105.                     $orderAdditional->execute();
  2106.                 } else {
  2107.                     $orderAdditional = $conn->prepare('UPDATE `order_item_additional` SET id_order_item = :id_order_item,id_additional = :id_additional,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_order_item_additional_off = :id  and id_company = :id_company');
  2108.                     $orderAdditional->bindValue(':id_order_item', $orderItemId['id']);
  2109.                     $orderAdditional->bindValue(':id', $itemAdditional['id']);
  2110.                     $orderAdditional->bindValue(':id_additional', $additionalId['id']);
  2111.                     $orderAdditional->bindValue(':id_company', $itemAdditional['id_company']);
  2112.                     $orderAdditional->bindValue(':sync', 'yes');
  2113.                     $orderAdditional->bindValue(':created_at', $itemAdditional['created_at']);
  2114.                     $orderAdditional->bindValue(':updated_at', $itemAdditional['updated_at']);
  2115.                     $orderAdditional->bindValue(':deleted_at', $itemAdditional['deleted_at']);
  2116.                    
  2117.                     $orderAdditional->execute();
  2118.                 }
  2119.             }
  2120.            
  2121.             foreach ($decodedResponse['preferences_items'] as $itemPreference) {
  2122.                 //seleciona o item do pedido
  2123.                 $selectOrderItem = $conn->prepare('SELECT id from order_item where id_company = :id_company and id_order_item_off = :id_order_item');
  2124.                 $selectOrderItem->bindValue(':id_company', $itemPreference['id_company']);
  2125.                 $selectOrderItem->bindValue(':id_order_item', $itemPreference['id_order_item']);
  2126.                
  2127.                 $selectOrderItem->execute();
  2128.                 $orderItemId = $selectOrderItem->fetch(PDO::FETCH_ASSOC);
  2129.                
  2130.                 //seleciona a preferencia
  2131.                 $selectPreference = $conn->prepare('SELECT id from preference where id_company = :id_company and id_preference_off = :id_preference');
  2132.                 $selectPreference->bindValue(':id_company', $itemPreference['id_company']);
  2133.                 $selectPreference->bindValue(':id_preference', $itemPreference['id_preference']);
  2134.                
  2135.                 $selectPreference->execute();
  2136.                 $preferenceId = $selectPreference->fetch(PDO::FETCH_ASSOC);
  2137.                
  2138.                 //seleciona o item da preferencia
  2139.                 $selectPreference = $conn->prepare('SELECT id from preference_item where id_company = :id_company and id_preference_item_off = :id_preference_item');
  2140.                 $selectPreference->bindValue(':id_company', $itemPreference['id_company']);
  2141.                 $selectPreference->bindValue(':id_preference_item', $itemPreference['id_preference_item']);
  2142.                
  2143.                 $selectPreference->execute();
  2144.                 $preferenceItemId = $selectPreference->fetch(PDO::FETCH_ASSOC);
  2145.                
  2146.                 if ($itemPreference['sync'] == 'never') {
  2147.                     $orderPreference = $conn->prepare('INSERT INTO `order_item_preference` (id_order_item_preference_off,id_company,id_order_item,id_preference,id_preference_item,sync,created_at,updated_at,deleted_at) VALUES (:id,:id_company,:id_order_item,:id_preference,:id_preference_item,:sync,:created_at,:updated_at,:deleted_at)');
  2148.                     $orderPreference->bindValue(':id_order_item', $orderItemId['id']);
  2149.                     $orderPreference->bindValue(':id_company', $itemPreference['id_company']);
  2150.                     $orderPreference->bindValue(':id', $itemPreference['id']);
  2151.                     $orderPreference->bindValue(':id_preference', $preferenceId['id']);
  2152.                     $orderPreference->bindValue(':id_preference_item', $preferenceItemId['id']);
  2153.                     $orderPreference->bindValue(':sync', 'yes');
  2154.                     $orderPreference->bindValue(':created_at', $itemPreference['created_at']);
  2155.                     $orderPreference->bindValue(':updated_at', $itemPreference['updated_at']);
  2156.                     $orderPreference->bindValue(':deleted_at', $itemPreference['deleted_at']);
  2157.                    
  2158.                     $orderPreference->execute();
  2159.                 } else {
  2160.                     $orderPreference = $conn->prepare('UPDATE `order_item_preference` SET id_order_item = :id_order_item,id_preference = :id_preference,id_preference_item = :id_preference_item,sync = :sync,created_at = :created_at,updated_at = :updated_at,deleted_at = :deleted_at WHERE id_order_item_preference_off = :id and id_company = :id_company');
  2161.                     $orderPreference->bindValue(':id_order_item', $orderItemId['id']);
  2162.                     $orderPreference->bindValue(':id_company', $itemPreference['id_company']);
  2163.                     $orderPreference->bindValue(':id', $itemPreference['id']);
  2164.                     $orderPreference->bindValue(':id_preference_item', $preferenceItemId['id']);
  2165.                     $orderPreference->bindValue(':id_preference', $preferenceId['id']);
  2166.                     $orderPreference->bindValue(':sync', 'yes');
  2167.                     $orderPreference->bindValue(':created_at', $itemPreference['created_at']);
  2168.                     $orderPreference->bindValue(':updated_at', $itemPreference['updated_at']);
  2169.                     $orderPreference->bindValue(':deleted_at', $itemPreference['deleted_at']);
  2170.                    
  2171.                     $orderPreference->execute();
  2172.                 }
  2173.             }
  2174.            
  2175.             $conn->commit();
  2176.             $list['error'] = 'false';
  2177.             return $list;
  2178.            
  2179.         }
  2180.         catch (Exception $e) {
  2181.             $conn->rollBack();
  2182.             $list['error'] = 'true';
  2183.             return $list;
  2184.         }
  2185.     }
  2186.    
  2187.     /**
  2188.      * Método utilizado para alterar todos os não sincronizados para sincronizados
  2189.      * @param  Request $request [description]
  2190.      * @return [type]           [description]
  2191.      */
  2192.     public function update(Request $request)
  2193.     {
  2194.        
  2195.         $conn = DatabaseUtils::getDB();
  2196.        
  2197.         $data      = $request->all();
  2198.         $companyId = $data['id_company'];
  2199.         $userId    = $data['userId'];
  2200.         $conn->beginTransaction();
  2201.         try {
  2202.             $stmt = $conn->prepare("SELECT  DISTINCT    COLUMN_NAME AS 'ColumnName'
  2203.            ,TABLE_NAME AS  'TableName'
  2204.            FROM        INFORMATION_SCHEMA.COLUMNS
  2205.            WHERE       COLUMN_NAME LIKE '%sync%'
  2206.            ORDER BY    TableName
  2207.                        ,ColumnName;");
  2208.             $stmt->execute();
  2209.             $update = $stmt->fetchAll(PDO::FETCH_ASSOC);
  2210.             foreach ($update as $as => $val) {
  2211.                 $table_name = $val['TableName'];
  2212.                
  2213.                 $query = 'UPDATE `' . $table_name . '` SET sync = :sync ';
  2214.                
  2215.                
  2216.                
  2217.                 $up = $conn->prepare($query);
  2218.                 $up->bindValue(':sync', 'yes');
  2219.                 $up->execute();
  2220.             }
  2221.            
  2222.             $sincStmt = $conn->prepare('INSERT INTO sincronize (id_company) VALUES (:id_company)');
  2223.             $sincStmt->bindValue(':id_company', $companyId);
  2224.            
  2225.             $sincStmt->execute();
  2226.            
  2227.             $response['error'] = false;
  2228.            
  2229.             $logSync = $conn->prepare('INSERT INTO company_log (id_user,id_company,page,message,subject,sync,created_at) VALUES (:id_user,:id_company,:page,:message,:subject,:sync,:created_at)');
  2230.             $logSync->bindValue(':id_user', $userId);
  2231.             $logSync->bindValue(':id_company', $companyId);
  2232.             $logSync->bindValue(':page', 'sincronizar');
  2233.             $logSync->bindValue(':message', 'Sincronização realizada com sucesso');
  2234.             $logSync->bindValue(':subject', 'Sincronização realizada');
  2235.             $logSync->bindValue(':sync', 'yes');
  2236.             $logSync->bindValue(':created_at', Carbon::now());
  2237.            
  2238.             $logSync->execute();
  2239.            
  2240.             $conn->commit();
  2241.             return json_encode($response);
  2242.         }
  2243.         catch (Exception $e) {
  2244.             $conn->rollBack();
  2245.             $response['error'] = true;
  2246.             return json_encode($response);
  2247.         }
  2248.     }
  2249.    
  2250.     /**
  2251.      * Método utilizado para selecionar todos não sincronizados
  2252.      * @param  [type] $companyId [description]
  2253.      * @return [type]            [description]
  2254.      */
  2255.     public function selectNoSync($companyId)
  2256.     {
  2257.         $conn = DatabaseUtils::getDB();
  2258.         $conn->beginTransaction();
  2259.        
  2260.         try {
  2261.             $additionalStmt = $conn->prepare('SELECT * FROM additional where sync = :sync and id_company = :id_company');
  2262.             $additionalStmt->bindValue(':sync', 'no');
  2263.             $additionalStmt->bindValue(':id_company', $companyId);
  2264.            
  2265.             $additionalStmt->execute();
  2266.             $additionals = $additionalStmt->fetchAll(PDO::FETCH_ASSOC);
  2267.            
  2268.             //passa os adicionais como indicé da variavel de retorno lista
  2269.             $list['additionals'] = $additionals;
  2270.            
  2271.             //BUSCA PELAS CATEGORIAS
  2272.             $categoryStmt = $conn->prepare('SELECT * from `category` where sync = :sync and id_company = :id_company');
  2273.             $categoryStmt->bindValue(':sync', 'no');
  2274.             $categoryStmt->bindValue(':id_company', $companyId);
  2275.            
  2276.             $categoryStmt->execute();
  2277.             $category = $categoryStmt->fetchAll(PDO::FETCH_ASSOC);
  2278.            
  2279.             $list['category'] = $category;
  2280.            
  2281.             //BUSCA PELAS EXIBIÇÕES DE CATEGORIAS
  2282.             $categoryExibitionStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `category_exibition` a inner join category on a.id_category = category.id where a.sync = :sync and a.id_company = :id_company');
  2283.             $categoryExibitionStmt->bindValue(':sync', 'no');
  2284.             $categoryExibitionStmt->bindValue(':id_company', $companyId);
  2285.            
  2286.             $categoryExibitionStmt->execute();
  2287.             $categoryExibition = $categoryExibitionStmt->fetchAll(PDO::FETCH_ASSOC);
  2288.            
  2289.             $list['category_exibition'] = $categoryExibition;
  2290.            
  2291.             //BUSCA PELAS COMANDAS
  2292.             $commandStmt = $conn->prepare('SELECT * from `command` where sync = :sync and id_company = :id_company');
  2293.             $commandStmt->bindValue(':sync', 'no');
  2294.             $commandStmt->bindValue(':id_company', $companyId);
  2295.            
  2296.             $commandStmt->execute();
  2297.             $command = $commandStmt->fetchAll(PDO::FETCH_ASSOC);
  2298.            
  2299.             $list['command'] = $command;
  2300.            
  2301.             //BUSCA PELAS MESAS DE COMANDAS
  2302.             $commandTableStmt = $conn->prepare('SELECT * from `command_table` where sync = :sync and id_company = :id_company');
  2303.             $commandTableStmt->bindValue(':sync', 'no');
  2304.             $commandTableStmt->bindValue(':id_company', $companyId);
  2305.            
  2306.             $commandTableStmt->execute();
  2307.             $commandTable = $commandTableStmt->fetchAll(PDO::FETCH_ASSOC);
  2308.            
  2309.             $list['command_table'] = $commandTable;
  2310.            
  2311.             //BUSCA PELAS EMPRESAS
  2312.             $companyStmt = $conn->prepare('SELECT * from `company` where sync = :sync and id = :id_company');
  2313.             $companyStmt->bindValue(':sync', 'no');
  2314.             $companyStmt->bindValue(':id_company', $companyId);
  2315.            
  2316.             $companyStmt->execute();
  2317.             $company = $companyStmt->fetchAll(PDO::FETCH_ASSOC);
  2318.            
  2319.             $list['company'] = $company;
  2320.            
  2321.             //BUSCA PELOS USUÁRIOS DAS EMPRESAS
  2322.             $companyUserStmt = $conn->prepare('SELECT * from `company_user` where sync = :sync and id_company = :id_company');
  2323.             $companyUserStmt->bindValue(':sync', 'no');
  2324.             $companyUserStmt->bindValue(':id_company', $companyId);
  2325.            
  2326.             $companyUserStmt->execute();
  2327.             $companyUser = $companyUserStmt->fetchAll(PDO::FETCH_ASSOC);
  2328.            
  2329.             $list['company_user'] = $companyUser;
  2330.            
  2331.             //BUSCA PELAS CONFIGURAÇÕES DAS EMPRESAS
  2332.             $configStmt = $conn->prepare('SELECT * from `config` where sync = :sync and id_company = :id_company');
  2333.             $configStmt->bindValue(':sync', 'no');
  2334.             $configStmt->bindValue(':id_company', $companyId);
  2335.            
  2336.             $configStmt->execute();
  2337.             $config = $configStmt->fetchAll(PDO::FETCH_ASSOC);
  2338.            
  2339.             $list['config'] = $config;
  2340.            
  2341.             //BUSCA PELOS TIPOS DE MENU
  2342.             $menuStmt = $conn->prepare('SELECT * from `menu_type` where sync = :sync and id_company = :id_company');
  2343.             $menuStmt->bindValue(':sync', 'no');
  2344.             $menuStmt->bindValue(':id_company', $companyId);
  2345.            
  2346.             $menuStmt->execute();
  2347.             $menu = $menuStmt->fetchAll(PDO::FETCH_ASSOC);
  2348.            
  2349.             $list['menu'] = $menu;
  2350.            
  2351.             //BUSCA PELAS PREFERÊNCIAS
  2352.             $preferenceStmt = $conn->prepare('SELECT * from `preference` where sync = :sync and id_company = :id_company');
  2353.             $preferenceStmt->bindValue(':sync', 'no');
  2354.             $preferenceStmt->bindValue(':id_company', $companyId);
  2355.            
  2356.             $preferenceStmt->execute();
  2357.             $preference = $preferenceStmt->fetchAll(PDO::FETCH_ASSOC);
  2358.            
  2359.             $list['preference'] = $preference;
  2360.            
  2361.             //BUSCA PELAS CATEGORIAS DAS PREFERÊNCIAS
  2362.             $preferenceCategoryStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `preference_category` a inner join preference on a.id_preference = preference.id inner join category on a.id_category = category.id where a.sync = :sync and a.id_company = :id_company');
  2363.             $preferenceCategoryStmt->bindValue(':sync', 'no');
  2364.             $preferenceCategoryStmt->bindValue(':id_company', $companyId);
  2365.            
  2366.             $preferenceCategoryStmt->execute();
  2367.             $preference_category = $preferenceCategoryStmt->fetchAll(PDO::FETCH_ASSOC);
  2368.            
  2369.             $list['preference_category'] = $preference_category;
  2370.            
  2371.             //BUSCA PELOS ITENS DAS PREFERÊNCIAS
  2372.             $preferenceItems = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `preference_item` a inner join preference on a.id_preference = preference.id where a.sync = :sync and a.id_company = :id_company');
  2373.             $preferenceItems->bindValue(':sync', 'no');
  2374.             $preferenceItems->bindValue(':id_company', $companyId);
  2375.            
  2376.             $preferenceItems->execute();
  2377.             $preference_item = $preferenceItems->fetchAll(PDO::FETCH_ASSOC);
  2378.            
  2379.             $list['preference_item'] = $preference_item;
  2380.            
  2381.             //BUSCA PELOS PRODUTOS
  2382.             $productsStmt = $conn->prepare('SELECT * from `product` where sync = :sync and id_company = :id_company');
  2383.             $productsStmt->bindValue(':sync', 'no');
  2384.             $productsStmt->bindValue(':id_company', $companyId);
  2385.            
  2386.             $productsStmt->execute();
  2387.             $products = $productsStmt->fetchAll(PDO::FETCH_ASSOC);
  2388.            
  2389.             $list['products'] = $products;
  2390.            
  2391.             //BUSCA PELOS ADICIONAIS DOS PRODUTOS
  2392.             $produtsAdditionalStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_additional` a inner join product on a.id_product = product.id inner join additional on a.id_additional = additional.id where a.sync = :sync and a.id_company = :id_company');
  2393.             $produtsAdditionalStmt->bindValue(':sync', 'no');
  2394.             $produtsAdditionalStmt->bindValue(':id_company', $companyId);
  2395.            
  2396.             $produtsAdditionalStmt->execute();
  2397.             $product_additionals = $produtsAdditionalStmt->fetchAll(PDO::FETCH_ASSOC);
  2398.            
  2399.             $list['product_additionals'] = $product_additionals;
  2400.            
  2401.             //BUSCA PELOS PLANOS DAS EMPRESAS
  2402.             $companyPlanStmt = $conn->prepare('SELECT * from `company_plan_type`');
  2403.            
  2404.             $companyPlanStmt->execute();
  2405.             $plantType = $companyPlanStmt->fetchAll(PDO::FETCH_ASSOC);
  2406.            
  2407.             $list['company_plan_type'] = $plantType;
  2408.            
  2409.             //BUSCA PELAS CATEGORIAS DOS PRODUTOS
  2410.             $productsCategoryStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_category` a inner join product on a.id_product = product.id inner join category on a.id_category = category.id where a.sync = :sync and a.id_company = :id_company');
  2411.             $productsCategoryStmt->bindValue(':sync', 'no');
  2412.             $productsCategoryStmt->bindValue(':id_company', $companyId);
  2413.            
  2414.             $productsCategoryStmt->execute();
  2415.             $product_category = $productsCategoryStmt->fetchAll(PDO::FETCH_ASSOC);
  2416.            
  2417.             $list['product_category'] = $product_category;
  2418.            
  2419.             //BUSCA PELAS IMAGENS DOS PRODUTOS
  2420.             $productImages = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_image` a inner join product on a.id_product = product.id where a.sync = :sync and a.id_company = :id_company');
  2421.             $productImages->bindValue(':sync', 'no');
  2422.             $productImages->bindValue(':id_company', $companyId);
  2423.            
  2424.             $productImages->execute();
  2425.             $product_image = $productImages->fetchAll(PDO::FETCH_ASSOC);
  2426.            
  2427.             $list['product_image'] = $product_image;
  2428.            
  2429.             //BUSCA PELAS EXIBIÇÕES DOS PRODUTOS
  2430.             $productsExibitionStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_exibition` a inner join product on a.id_product = product.id where a.id_company = :id_company and a.sync = :sync');
  2431.            
  2432.             $productsExibitionStmt->bindValue(':id_company', $companyId);
  2433.             $productsExibitionStmt->bindValue(':sync', 'no');
  2434.            
  2435.             $productsExibitionStmt->execute();
  2436.             $product_exibition = $productsExibitionStmt->fetchAll(PDO::FETCH_ASSOC);
  2437.            
  2438.             $list['product_exibition'] = $product_exibition;
  2439.            
  2440.             //BUSCA PELAS PREFERÊNCIAS DOS PRODUTOS
  2441.             $productPreference = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_preference` a inner join product on a.id_product = product.id inner join preference on a.id_preference = preference.id where a.sync = :sync and a.id_company = :id_company');
  2442.             $productPreference->bindValue(':sync', 'no');
  2443.             $productPreference->bindValue(':id_company', $companyId);
  2444.            
  2445.             $productPreference->execute();
  2446.             $product_preference = $productPreference->fetchAll(PDO::FETCH_ASSOC);
  2447.            
  2448.             $list['product_preference'] = $product_preference;
  2449.            
  2450.             //BUSCA PELAS VENDAS DOS PRODUTOS
  2451.             $productSales = $conn->prepare('SELECT *,a.id,a.sync from `product_sale` a inner join product on a.id_product = product.id inner join sale_type on a.id_sale_type = sale_type.id where a.sync = :sync and a.id_company = :id_company');
  2452.             $productSales->bindValue(':sync', 'no');
  2453.             $productSales->bindValue(':id_company', $companyId);
  2454.            
  2455.             $productSales->execute();
  2456.             $product_sales = $productSales->fetchAll(PDO::FETCH_ASSOC);
  2457.            
  2458.             $list['product_sales'] = $product_sales;
  2459.            
  2460.             //BUSCA PELAS TAGS DOS PRODUTOS
  2461.             $productTags = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_tag` a inner join product on a.id_product = product.id where a.sync = :sync and a.id_company = :id_company');
  2462.             $productTags->bindValue(':sync', 'no');
  2463.             $productTags->bindValue(':id_company', $companyId);
  2464.            
  2465.             $productTags->execute();
  2466.             $product_tags = $productTags->fetchAll(PDO::FETCH_ASSOC);
  2467.            
  2468.             $list['product_tags'] = $product_tags;
  2469.            
  2470.             //BUSCA PELOS TIPOS DOS PRODUTOS
  2471.             $productType = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_type` a inner join product on a.id_product = product.id where a.sync = :sync and a.id_company = :id_company');
  2472.             $productType->bindValue(':sync', 'no');
  2473.             $productType->bindValue(':id_company', $companyId);
  2474.            
  2475.             $productType->execute();
  2476.             $product_types = $productType->fetchAll(PDO::FETCH_ASSOC);
  2477.            
  2478.             $list['product_types'] = $product_types;
  2479.            
  2480.             //BUSCA PELOS TIPOS De VENDAS
  2481.             $saleType = $conn->prepare('SELECT * from `sale_type` where sync = :sync and id_company = :id_company');
  2482.             $saleType->bindValue(':sync', 'no');
  2483.             $saleType->bindValue(':id_company', $companyId);
  2484.            
  2485.             $saleType->execute();
  2486.             $sale_type = $saleType->fetchAll(PDO::FETCH_ASSOC);
  2487.            
  2488.             $list['sale_type'] = $sale_type;
  2489.            
  2490.             //BUSCA PELAS MESAS
  2491.             $tableStmt = $conn->prepare('SELECT * from `table` where sync = :sync and id_company = :id_company');
  2492.             $tableStmt->bindValue(':sync', 'no');
  2493.             $tableStmt->bindValue(':id_company', $companyId);
  2494.            
  2495.             $tableStmt->execute();
  2496.             $table = $tableStmt->fetchAll(PDO::FETCH_ASSOC);
  2497.            
  2498.             $list['table'] = $table;
  2499.            
  2500.             //BUSCA PELAS MESAS
  2501.             $tagStmt = $conn->prepare('SELECT * from `tag` where sync = :sync ');
  2502.             $tagStmt->bindValue(':sync', 'no');
  2503.            
  2504.             $tagStmt->execute();
  2505.             $tag = $tagStmt->fetchAll(PDO::FETCH_ASSOC);
  2506.            
  2507.             $list['tag'] = $tag;
  2508.            
  2509.             //BUSCA PELAS TIPOS DE AUDIÊNCIAS
  2510.             $target = $conn->prepare('SELECT * from `target_audience` where sync = :sync and id_company = :id_company');
  2511.             $target->bindValue(':sync', 'no');
  2512.             $target->bindValue(':id_company', $companyId);
  2513.            
  2514.             $target->execute();
  2515.             $targetAudience = $target->fetchAll(PDO::FETCH_ASSOC);
  2516.            
  2517.             $list['target'] = $targetAudience;
  2518.            
  2519.             //BUSCA PELOS COMBOS
  2520.             $comboStmt = $conn->prepare('SELECT * from `combo` where sync = :sync and id_company = :id_company');
  2521.             $comboStmt->bindValue(':sync', 'no');
  2522.             $comboStmt->bindValue(':id_company', $companyId);
  2523.            
  2524.             $comboStmt->execute();
  2525.             $combo = $comboStmt->fetchAll(PDO::FETCH_ASSOC);
  2526.            
  2527.             $list['combo'] = $combo;
  2528.            
  2529.             //BUSCA PELOS COMBOS
  2530.             $comboGroup = $conn->prepare('SELECT *,a.name,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `combo_group` a inner join combo on a.combo_id = combo.id  where a.sync = :sync and a.company_id = :id_company');
  2531.             $comboGroup->bindValue(':sync', 'no');
  2532.             $comboGroup->bindValue(':id_company', $companyId);
  2533.            
  2534.             $comboGroup->execute();
  2535.             $combo = $comboGroup->fetchAll(PDO::FETCH_ASSOC);
  2536.            
  2537.             $list['combo_group'] = $combo;
  2538.            
  2539.             //BUSCA PELOS COMBOS
  2540.             $comboGroupItem = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `combo_group_item` a inner join combo_group on a.combo_group_id = combo_group.id inner join product on a.product_id = product.id where a.sync = :sync and a.company_id = :id_company');
  2541.             $comboGroupItem->bindValue(':sync', 'no');
  2542.             $comboGroupItem->bindValue(':id_company', $companyId);
  2543.            
  2544.             $comboGroupItem->execute();
  2545.             $combo = $comboGroupItem->fetchAll(PDO::FETCH_ASSOC);
  2546.            
  2547.             $list['combo_group_item'] = $combo;
  2548.            
  2549.             //BUSCA PELOS COMBOS
  2550.             $comboType = $conn->prepare('SELECT *,a.id,a.name,a.deleted_at,a.created_at,a.updated_at,a.sync from `combo_type` a inner join combo on a.combo_id = combo.id where a.sync = :sync and a.company_id = :id_company');
  2551.             $comboType->bindValue(':sync', 'no');
  2552.             $comboType->bindValue(':id_company', $companyId);
  2553.            
  2554.             $comboType->execute();
  2555.             $combo = $comboType->fetchAll(PDO::FETCH_ASSOC);
  2556.            
  2557.             $list['combo_type'] = $combo;
  2558.            
  2559.             //BUSCA PELOS COMBOS
  2560.             $comboType = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `combo_image` a inner join combo on a.id_combo = combo.id where a.sync = :sync and a.id_company = :id_company');
  2561.             $comboType->bindValue(':sync', 'no');
  2562.             $comboType->bindValue(':id_company', $companyId);
  2563.            
  2564.             $comboType->execute();
  2565.             $combo = $comboType->fetchAll(PDO::FETCH_ASSOC);
  2566.            
  2567.             $list['combo_image'] = $combo;
  2568.            
  2569.             //BUSCA PELOS COMBOS
  2570.             $comboExibition = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `combo_exibition` a inner join combo on a.combo_id = combo.id where a.sync = :sync and a.company_id = :id_company');
  2571.             $comboExibition->bindValue(':sync', 'no');
  2572.             $comboExibition->bindValue(':id_company', $companyId);
  2573.            
  2574.             $comboExibition->execute();
  2575.             $combo = $comboExibition->fetchAll(PDO::FETCH_ASSOC);
  2576.            
  2577.             $list['combo_exibition'] = $combo;
  2578.            
  2579.             //BUSCA PELAS CAMPANHAS
  2580.             $campaignStmt = $conn->prepare('SELECT * from `campaign` where sync = :sync and exists (select * from campaign_company where id_company = :company_id and id_campaign = campaign.id) ');
  2581.             $campaignStmt->bindValue(':sync', 'no');
  2582.             $campaignStmt->bindValue(':company_id', $companyId);
  2583.            
  2584.             $campaignStmt->execute();
  2585.             $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
  2586.            
  2587.             $list['campaign'] = $campaign;
  2588.            
  2589.             //BUSCA PELAS EMPRESAS PARA INSERIR AS CAMPANHAS
  2590.             $campaignStmt = $conn->prepare('SELECT * from campaign_company where id_company = :company_id and sync = :sync');
  2591.             $campaignStmt->bindValue(':sync', 'no');
  2592.             $campaignStmt->bindValue(':company_id', $companyId);
  2593.            
  2594.             $campaignStmt->execute();
  2595.             $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
  2596.            
  2597.             $list['campaign_company'] = $campaign;
  2598.            
  2599.             //BUSCA PELAS campanhas de empresas
  2600.             $campaignStmt = $conn->prepare('SELECT * from restaurant_campaign where id_company = :company_id and sync = :sync');
  2601.             $campaignStmt->bindValue(':sync', 'no');
  2602.             $campaignStmt->bindValue(':company_id', $companyId);
  2603.            
  2604.             $campaignStmt->execute();
  2605.             $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
  2606.            
  2607.             $list['restaurant_campaign'] = $campaign;
  2608.            
  2609.             //BUSCA PELAS PRODUTOS CADASTRADOS EM CAMPANHAS DE EMPRESAS
  2610.             $campaignStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from restaurant_campaign_product a inner join restaurant_campaign on a.id_campaign = restaurant_campaign.id inner join product on a.id_product = product.id where a.id_company = :company_id and a.sync = :sync');
  2611.             $campaignStmt->bindValue(':sync', 'no');
  2612.             $campaignStmt->bindValue(':company_id', $companyId);
  2613.            
  2614.             $campaignStmt->execute();
  2615.             $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
  2616.            
  2617.             $list['restaurant_campaign_product'] = $campaign;
  2618.            
  2619.             $conn->commit();
  2620.  
  2621.             return $list;
  2622.         }
  2623.         catch (Exception $e) {
  2624.             $conn->rollBack();
  2625.             return ApiResponse::returnResponse(true, $e->getMessage(), null);
  2626.            
  2627.         }
  2628.     }
  2629.    
  2630.     /**
  2631.      * Método que seleciona dados nunca sincronizados
  2632.      * @param  [type] $companyId [description]
  2633.      * @return [type]            [description]
  2634.      */
  2635.     public function selectNeverSync($companyId)
  2636.     {
  2637.         $conn = DatabaseUtils::getDB();
  2638.         $conn->beginTransaction();
  2639.         try {
  2640.             $additionalStmt = $conn->prepare('SELECT * FROM additional where sync = :sync and id_company = :id_company');
  2641.             $additionalStmt->bindValue(':sync', 'never');
  2642.             $additionalStmt->bindValue(':id_company', $companyId);
  2643.            
  2644.             $additionalStmt->execute();
  2645.             $additionals = $additionalStmt->fetchAll(PDO::FETCH_ASSOC);
  2646.            
  2647.             //passa os adicionais como indicé da variavel de retorno lista
  2648.             $list['additionals'] = $additionals;
  2649.            
  2650.             //BUSCA PELAS CATEGORIAS
  2651.             $categoryStmt = $conn->prepare('SELECT * from `category` where sync = :sync and id_company = :id_company');
  2652.             $categoryStmt->bindValue(':sync', 'never');
  2653.             $categoryStmt->bindValue(':id_company', $companyId);
  2654.            
  2655.             $categoryStmt->execute();
  2656.             $category = $categoryStmt->fetchAll(PDO::FETCH_ASSOC);
  2657.            
  2658.             $list['category'] = $category;
  2659.            
  2660.             //BUSCA PELAS EXIBIÇÕES DE CATEGORIAS
  2661.             $categoryExibitionStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `category_exibition` a inner join category on a.id_category = category.id  where a.sync = :sync and a.id_company = :id_company');
  2662.             $categoryExibitionStmt->bindValue(':sync', 'never');
  2663.             $categoryExibitionStmt->bindValue(':id_company', $companyId);
  2664.            
  2665.             $categoryExibitionStmt->execute();
  2666.             $categoryExibition = $categoryExibitionStmt->fetchAll(PDO::FETCH_ASSOC);
  2667.            
  2668.             $list['category_exibition'] = $categoryExibition;
  2669.            
  2670.             //BUSCA PELAS COMANDAS
  2671.             $commandStmt = $conn->prepare('SELECT * from `command` where sync = :sync and id_company = :id_company');
  2672.             $commandStmt->bindValue(':sync', 'never');
  2673.             $commandStmt->bindValue(':id_company', $companyId);
  2674.            
  2675.             $commandStmt->execute();
  2676.             $command = $commandStmt->fetchAll(PDO::FETCH_ASSOC);
  2677.            
  2678.             $list['command'] = $command;
  2679.            
  2680.             //BUSCA PELAS MESAS DE COMANDAS
  2681.             $commandTableStmt = $conn->prepare('SELECT * from `command_table` where sync = :sync and id_company = :id_company');
  2682.             $commandTableStmt->bindValue(':sync', 'never');
  2683.             $commandTableStmt->bindValue(':id_company', $companyId);
  2684.            
  2685.             $commandTableStmt->execute();
  2686.             $commandTable = $commandTableStmt->fetchAll(PDO::FETCH_ASSOC);
  2687.            
  2688.             $list['command_table'] = $commandTable;
  2689.            
  2690.             //BUSCA PELAS EMPRESAS
  2691.             $companyStmt = $conn->prepare('SELECT * from `company` where sync = :sync and id = :id_company');
  2692.             $companyStmt->bindValue(':sync', 'never');
  2693.             $companyStmt->bindValue(':id_company', $companyId);
  2694.            
  2695.             $companyStmt->execute();
  2696.             $company = $companyStmt->fetchAll(PDO::FETCH_ASSOC);
  2697.            
  2698.             $list['company'] = $company;
  2699.            
  2700.             //BUSCA PELOS USUÁRIOS DAS EMPRESAS
  2701.             $companyUserStmt = $conn->prepare('SELECT * from `company_user` where sync = :sync and id_company = :id_company');
  2702.             $companyUserStmt->bindValue(':sync', 'never');
  2703.             $companyUserStmt->bindValue(':id_company', $companyId);
  2704.            
  2705.             $companyUserStmt->execute();
  2706.             $companyUser = $companyUserStmt->fetchAll(PDO::FETCH_ASSOC);
  2707.            
  2708.             $list['company_user'] = $companyUser;
  2709.            
  2710.             //BUSCA PELAS CONFIGURAÇÕES DAS EMPRESAS
  2711.             $configStmt = $conn->prepare('SELECT * from `config` where sync = :sync and id_company = :id_company');
  2712.             $configStmt->bindValue(':sync', 'never');
  2713.             $configStmt->bindValue(':id_company', $companyId);
  2714.            
  2715.             $configStmt->execute();
  2716.             $config = $configStmt->fetchAll(PDO::FETCH_ASSOC);
  2717.            
  2718.             $list['config'] = $config;
  2719.            
  2720.             //BUSCA PELOS TIPOS DE MENU
  2721.             $menuStmt = $conn->prepare('SELECT * from `menu_type` where sync = :sync and id_company = :id_company');
  2722.             $menuStmt->bindValue(':sync', 'never');
  2723.             $menuStmt->bindValue(':id_company', $companyId);
  2724.            
  2725.             $menuStmt->execute();
  2726.             $menu = $menuStmt->fetchAll(PDO::FETCH_ASSOC);
  2727.            
  2728.             $list['menu'] = $menu;
  2729.            
  2730.             //BUSCA PELAS PREFERÊNCIAS
  2731.             $preferenceStmt = $conn->prepare('SELECT * from `preference` where sync = :sync and id_company = :id_company');
  2732.             $preferenceStmt->bindValue(':sync', 'never');
  2733.             $preferenceStmt->bindValue(':id_company', $companyId);
  2734.            
  2735.             $preferenceStmt->execute();
  2736.             $preference = $preferenceStmt->fetchAll(PDO::FETCH_ASSOC);
  2737.            
  2738.             $list['preference'] = $preference;
  2739.            
  2740.             //BUSCA PELAS CATEGORIAS DAS PREFERÊNCIAS
  2741.             $preferenceCategoryStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `preference_category` a  inner join category  on a.id_category = category.id inner join preference on a.id_preference = preference.id where a.sync = :sync and a.id_company = :id_company');
  2742.             $preferenceCategoryStmt->bindValue(':sync', 'never');
  2743.             $preferenceCategoryStmt->bindValue(':id_company', $companyId);
  2744.            
  2745.             $preferenceCategoryStmt->execute();
  2746.             $preference_category = $preferenceCategoryStmt->fetchAll(PDO::FETCH_ASSOC);
  2747.            
  2748.             $list['preference_category'] = $preference_category;
  2749.            
  2750.             //BUSCA PELOS ITENS DAS PREFERÊNCIAS
  2751.             $preferenceItems = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `preference_item` a  inner join preference on a.id_preference = preference.id where a.sync = :sync and a.id_company = :id_company');
  2752.             $preferenceItems->bindValue(':sync', 'never');
  2753.             $preferenceItems->bindValue(':id_company', $companyId);
  2754.            
  2755.             $preferenceItems->execute();
  2756.             $preference_item = $preferenceItems->fetchAll(PDO::FETCH_ASSOC);
  2757.            
  2758.             $list['preference_item'] = $preference_item;
  2759.            
  2760.             //BUSCA PELOS PRODUTOS
  2761.             $productsStmt = $conn->prepare('SELECT * from `product` where sync = :sync and id_company = :id_company');
  2762.             $productsStmt->bindValue(':sync', 'never');
  2763.             $productsStmt->bindValue(':id_company', $companyId);
  2764.            
  2765.             $productsStmt->execute();
  2766.             $products = $productsStmt->fetchAll(PDO::FETCH_ASSOC);
  2767.            
  2768.             $list['products'] = $products;
  2769.            
  2770.             //BUSCA PELOS ADICIONAIS DOS PRODUTOS
  2771.             $produtsAdditionalStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_additional` a  inner join additional  on a.id_additional = additional.id inner join product on a.id_product = product.id where a.sync = :sync and a.id_company = :id_company');
  2772.             $produtsAdditionalStmt->bindValue(':sync', 'never');
  2773.             $produtsAdditionalStmt->bindValue(':id_company', $companyId);
  2774.            
  2775.             $produtsAdditionalStmt->execute();
  2776.             $product_additionals = $produtsAdditionalStmt->fetchAll(PDO::FETCH_ASSOC);
  2777.            
  2778.             $list['product_additionals'] = $product_additionals;
  2779.            
  2780.             //BUSCA PELOS PLANOS DAS EMPRESAS
  2781.             $companyPlanStmt = $conn->prepare('SELECT * from `company_plan_type`');
  2782.            
  2783.             $companyPlanStmt->execute();
  2784.             $plantType = $companyPlanStmt->fetchAll(PDO::FETCH_ASSOC);
  2785.            
  2786.             $list['company_plan_type'] = $plantType;
  2787.            
  2788.             //BUSCA PELAS CATEGORIAS DOS PRODUTOS
  2789.             $productsCategoryStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_category` a  inner join category  on a.id_category = category.id inner join product on a.id_product = product.id where a.sync = :sync and a.id_company = :id_company');
  2790.             $productsCategoryStmt->bindValue(':sync', 'never');
  2791.             $productsCategoryStmt->bindValue(':id_company', $companyId);
  2792.            
  2793.             $productsCategoryStmt->execute();
  2794.             $product_category = $productsCategoryStmt->fetchAll(PDO::FETCH_ASSOC);
  2795.            
  2796.             $list['product_category'] = $product_category;
  2797.            
  2798.            
  2799.             //TODOS OS REGISTROS DE LOG
  2800.             $localLogStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from  `company_log` a inner join company_user on a.id_user = company_user.id WHERE a.id_company = :id_company AND a.sync = :sync');
  2801.             $localLogStmt->bindValue(':id_company', $companyId);
  2802.             $localLogStmt->bindValue('sync', 'never');
  2803.            
  2804.             $localLogStmt->execute();
  2805.             $logList = $localLogStmt->fetchAll(PDO::FETCH_ASSOC);
  2806.            
  2807.             $list['company_log'] = $logList;
  2808.            
  2809.             //BUSCA PELAS IMAGENS DOS PRODUTOS
  2810.             $productImages = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_image` a  inner join product on a.id_product = product.id where a.sync = :sync and a.id_company = :id_company');
  2811.             $productImages->bindValue(':sync', 'never');
  2812.             $productImages->bindValue(':id_company', $companyId);
  2813.            
  2814.             $productImages->execute();
  2815.             $product_image = $productImages->fetchAll(PDO::FETCH_ASSOC);
  2816.            
  2817.             $list['product_image'] = $product_image;
  2818.            
  2819.             //BUSCA PELAS EXIBIÇÕES DOS PRODUTOS
  2820.             $productsExibitionStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_exibition` a  inner join product on a.id_product = product.id where a.id_company = :id_company and a.sync = :sync');
  2821.            
  2822.             $productsExibitionStmt->bindValue(':id_company', $companyId);
  2823.             $productsExibitionStmt->bindValue(':sync', 'never');
  2824.            
  2825.             $productsExibitionStmt->execute();
  2826.             $product_exibition = $productsExibitionStmt->fetchAll(PDO::FETCH_ASSOC);
  2827.            
  2828.             $list['product_exibition'] = $product_exibition;
  2829.            
  2830.             //BUSCA PELAS PREFERÊNCIAS DOS PRODUTOS
  2831.             $productPreference = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_preference` a  inner join product on a.id_product = product.id inner join preference on a.id_preference = preference.id where a.sync = :sync and a.id_company = :id_company');
  2832.             $productPreference->bindValue(':sync', 'never');
  2833.             $productPreference->bindValue(':id_company', $companyId);
  2834.            
  2835.             $productPreference->execute();
  2836.             $product_preference = $productPreference->fetchAll(PDO::FETCH_ASSOC);
  2837.            
  2838.             $list['product_preference'] = $product_preference;
  2839.            
  2840.             //BUSCA PELAS VENDAS DOS PRODUTOS
  2841.             $productSales = $conn->prepare('SELECT *,a.id,a.sync from `product_sale` a inner join sale_type on a.id_sale_type = sale_type.id inner join product on a.id_product = product.id where a.sync = :sync and a.id_company = :id_company');
  2842.             $productSales->bindValue(':sync', 'never');
  2843.             $productSales->bindValue(':id_company', $companyId);
  2844.            
  2845.             $productSales->execute();
  2846.             $product_sales = $productSales->fetchAll(PDO::FETCH_ASSOC);
  2847.            
  2848.             $list['product_sales'] = $product_sales;
  2849.            
  2850.             //BUSCA PELAS TAGS DOS PRODUTOS
  2851.             $productTags = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_tag` a inner join product on a.id_product = product.id where a.sync = :sync and a.id_company = :id_company');
  2852.             $productTags->bindValue(':sync', 'never');
  2853.             $productTags->bindValue(':id_company', $companyId);
  2854.            
  2855.             $productTags->execute();
  2856.             $product_tags = $productTags->fetchAll(PDO::FETCH_ASSOC);
  2857.            
  2858.             $list['product_tags'] = $product_tags;
  2859.            
  2860.             //BUSCA PELOS TIPOS DOS PRODUTOS
  2861.             $productType = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `product_type` a inner join product on a.id_product = product.id where a.sync = :sync and a.id_company = :id_company');
  2862.             $productType->bindValue(':sync', 'never');
  2863.             $productType->bindValue(':id_company', $companyId);
  2864.            
  2865.             $productType->execute();
  2866.             $product_types = $productType->fetchAll(PDO::FETCH_ASSOC);
  2867.            
  2868.             $list['product_types'] = $product_types;
  2869.            
  2870.             //BUSCA PELOS TIPOS De VENDAS
  2871.             $saleType = $conn->prepare('SELECT * from `sale_type` where sync = :sync and id_company = :id_company');
  2872.             $saleType->bindValue(':sync', 'never');
  2873.             $saleType->bindValue(':id_company', $companyId);
  2874.            
  2875.            
  2876.             $saleType->execute();
  2877.             $sale_type = $saleType->fetchAll(PDO::FETCH_ASSOC);
  2878.            
  2879.             $list['sale_type'] = $sale_type;
  2880.            
  2881.             //BUSCA PELAS MESAS
  2882.             $tableStmt = $conn->prepare('SELECT * from `table` where sync = :sync and id_company = :id_company');
  2883.             $tableStmt->bindValue(':sync', 'never');
  2884.             $tableStmt->bindValue(':id_company', $companyId);
  2885.            
  2886.            
  2887.             $tableStmt->execute();
  2888.             $table = $tableStmt->fetchAll(PDO::FETCH_ASSOC);
  2889.            
  2890.             $list['table'] = $table;
  2891.            
  2892.             //BUSCA PELAS MESAS
  2893.             $tagStmt = $conn->prepare('SELECT * from `tag` where sync = :sync ');
  2894.             $tagStmt->bindValue(':sync', 'never');
  2895.            
  2896.            
  2897.             $tagStmt->execute();
  2898.             $tag = $tagStmt->fetchAll(PDO::FETCH_ASSOC);
  2899.            
  2900.             $list['tag'] = $tag;
  2901.            
  2902.             //BUSCA PELAS TIPOS DE AUDIÊNCIAS
  2903.             $target = $conn->prepare('SELECT * from `target_audience` where sync = :sync and id_company = :id_company');
  2904.             $target->bindValue(':sync', 'never');
  2905.             $target->bindValue(':id_company', $companyId);
  2906.            
  2907.            
  2908.             $target->execute();
  2909.             $targetAudience = $target->fetchAll(PDO::FETCH_ASSOC);
  2910.            
  2911.             $list['target'] = $targetAudience;
  2912.            
  2913.             //BUSCA PELOS COMBOS
  2914.             $comboStmt = $conn->prepare('SELECT * from `combo` where sync = :sync and id_company = :id_company');
  2915.             $comboStmt->bindValue(':sync', 'never');
  2916.             $comboStmt->bindValue(':id_company', $companyId);
  2917.            
  2918.            
  2919.             $comboStmt->execute();
  2920.             $combo = $comboStmt->fetchAll(PDO::FETCH_ASSOC);
  2921.            
  2922.             $list['combo'] = $combo;
  2923.            
  2924.             //BUSCA PELOS COMBOS
  2925.             $comboGroup = $conn->prepare('SELECT *,a.id,a.name,a.deleted_at,a.created_at,a.updated_at,a.sync from `combo_group` a inner join combo on a.combo_id = combo.id where a.sync = :sync and a.company_id = :id_company');
  2926.             $comboGroup->bindValue(':sync', 'never');
  2927.             $comboGroup->bindValue(':id_company', $companyId);
  2928.            
  2929.            
  2930.             $comboGroup->execute();
  2931.             $combo = $comboGroup->fetchAll(PDO::FETCH_ASSOC);
  2932.            
  2933.             $list['combo_group'] = $combo;
  2934.            
  2935.             //BUSCA PELOS COMBOS
  2936.             $comboGroupItem = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `combo_group_item` a inner join combo_group on a.combo_group_id = combo_group.id inner join product on a.product_id = product.id where a.sync = :sync and a.company_id = :id_company');
  2937.             $comboGroupItem->bindValue(':sync', 'never');
  2938.             $comboGroupItem->bindValue(':id_company', $companyId);
  2939.            
  2940.            
  2941.             $comboGroupItem->execute();
  2942.             $combo = $comboGroupItem->fetchAll(PDO::FETCH_ASSOC);
  2943.            
  2944.             $list['combo_group_item'] = $combo;
  2945.            
  2946.            
  2947.             //BUSCA PELOS COMBOS
  2948.             $comboType = $conn->prepare('SELECT *,a.id,a.name,a.deleted_at,a.created_at,a.updated_at,a.sync,a.price from `combo_type` a inner join combo on a.combo_id  = combo.id where a.sync = :sync and a.company_id = :id_company');
  2949.             $comboType->bindValue(':sync', 'never');
  2950.             $comboType->bindValue(':id_company', $companyId);
  2951.            
  2952.            
  2953.             $comboType->execute();
  2954.             $combo = $comboType->fetchAll(PDO::FETCH_ASSOC);
  2955.            
  2956.             $list['combo_type'] = $combo;
  2957.            
  2958.             //BUSCA PELOS COMBOS
  2959.             $comboExibition = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `combo_exibition` a inner join combo on a.combo_id = combo.id  where a.sync = :sync and a.company_id = :id_company');
  2960.             $comboExibition->bindValue(':sync', 'never');
  2961.             $comboExibition->bindValue(':id_company', $companyId);
  2962.            
  2963.            
  2964.             $comboExibition->execute();
  2965.             $combo = $comboExibition->fetchAll(PDO::FETCH_ASSOC);
  2966.            
  2967.             $list['combo_exibition'] = $combo;
  2968.            
  2969.             //BUSCA PELAS IMAGENS DOS COMBOS
  2970.             $comboImage = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from `combo_image` a inner join combo on a.id_combo = combo.id where a.sync = :sync and a.id_company = :id_company');
  2971.             $comboImage->bindValue(':sync', 'never');
  2972.             $comboImage->bindValue(':id_company', $companyId);
  2973.            
  2974.             $comboImage->execute();
  2975.             $combo = $comboImage->fetchAll(PDO::FETCH_ASSOC);
  2976.            
  2977.             $list['combo_image'] = $combo;
  2978.            
  2979.             //BUSCA PELAS CAMPANHAS
  2980.             $campaignStmt = $conn->prepare('SELECT * from `campaign` where sync = :sync and exists (select * from campaign_company where id_company = :company_id and id_campaign = campaign.id) ');
  2981.             $campaignStmt->bindValue(':sync', 'never');
  2982.             $campaignStmt->bindValue(':company_id', $companyId);
  2983.            
  2984.             $campaignStmt->execute();
  2985.             $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
  2986.            
  2987.             $list['campaign'] = $campaign;
  2988.            
  2989.             //BUSCA PELAS EMPRESAS PARA INSERIR AS CAMPANHAS
  2990.             $campaignStmt = $conn->prepare('SELECT * from campaign_company where id_company = :company_id and sync = :sync');
  2991.             $campaignStmt->bindValue(':sync', 'never');
  2992.             $campaignStmt->bindValue(':company_id', $companyId);
  2993.            
  2994.             $campaignStmt->execute();
  2995.             $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
  2996.            
  2997.             $list['campaign_company'] = $campaign;
  2998.            
  2999.             //BUSCA PELAS campanhas de empresas
  3000.             $campaignStmt = $conn->prepare('SELECT * from restaurant_campaign where id_company = :company_id and sync = :sync');
  3001.             $campaignStmt->bindValue(':sync', 'never');
  3002.             $campaignStmt->bindValue(':company_id', $companyId);
  3003.            
  3004.             $campaignStmt->execute();
  3005.             $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
  3006.            
  3007.             $list['restaurant_campaign'] = $campaign;
  3008.            
  3009.            
  3010.             //BUSCA PELAS PRODUTOS CADASTRADOS EM CAMPANHAS DE EMPRESAS
  3011.             $campaignStmt = $conn->prepare('SELECT *,a.id,a.deleted_at,a.created_at,a.updated_at,a.sync from restaurant_campaign_product a inner join restaurant_campaign on a.id_campaign = restaurant_campaign.id inner join product on a.id_product = product.id  where a.id_company = :company_id and a.sync = :sync');
  3012.             $campaignStmt->bindValue(':sync', 'never');
  3013.             $campaignStmt->bindValue(':company_id', $companyId);
  3014.            
  3015.             $campaignStmt->execute();
  3016.             $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
  3017.            
  3018.             $list['restaurant_campaign_product'] = $campaign;
  3019.             $list['error']                       = false;
  3020.             $conn->commit();
  3021.             return $list;
  3022.         }
  3023.         catch (Exception $e) {
  3024.             $list['error'] = true;
  3025.             $conn->rollBack();
  3026.             return $list;
  3027.         }
  3028.     }
  3029. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement