Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * Classe para manipular os logs da dashboard
- *
- * @author Gabriel Moraes <gabriel.baptista@inside-estudio.com.br>
- */
- namespace App\Http\Controllers\Sync;
- use Illuminate\Http\Request;
- use App\Http\Controllers\Controller;
- use Illuminate\Support\Facades\DB;
- use App\Utils\ApiResponse;
- use App\Utils\DatabaseUtils;
- use App\Utils\GetFile;
- use Carbon\Carbon;
- use \PDO;
- class SyncController extends Controller
- {
- private $address;
- private function downloadImage($image)
- {
- $gf = new GetFile($this->address);
- $gf->download($image);
- }
- /**
- * Método utilizado para sincronizar os bancos de dados
- * @param Request $request [description]
- * @return [type] [description]
- */
- public function sync(Request $request)
- {
- $data = $request->all();
- $companyId = $data['items']['id_company'];
- $this->address = $data['address'];
- $updateNewItems = $this->updateNewItems($data['update_new']);
- $verifySync = $this->insertIntoOnline($data['items']);
- $selectSync = $this->selectNoSync($companyId);
- $returnSelect['items'] = $selectSync;
- $returnSelect['insert'] = $verifySync;
- // print_r($returnSelect['insert']);die();
- return json_encode($returnSelect);
- }
- public function syncNewItems(Request $request)
- {
- $data = $request->all();
- $companyId = $data['id_company'];
- $list = $this->selectNeverSync($companyId);
- return json_encode($list);
- // return json_encode($list, JSON_PRETTY_PRINT);
- }
- /**
- * Método utilizado para sincronizar dados que foram inseridos na off para online
- * @param [type] $decodedResponse [description]
- * @return [type] [description]
- */
- public function updateNewItems($decodedResponse) {
- $conn = DatabaseUtils::getDB();
- $conn->beginTransaction();
- try {
- //ADICIONAIS
- foreach ($decodedResponse['additionals'] as $additional) {
- $insertAdditional = $conn->prepare('UPDATE `additional` SET id_additional_off = :id_off , sync = :sync WHERE id = :online_id');
- $insertAdditional->bindValue(':online_id', $additional['online_id']);
- $insertAdditional->bindValue(':id_off', $additional['id_off']);
- $insertAdditional->bindValue(':sync', 'yes');
- $insertAdditional->execute();
- }
- //CATEGORIAS
- foreach ($decodedResponse['category'] as $category) {
- $insertCategory = $conn->prepare('UPDATE `category` SET sync = :sync, id_category_off = :id_off WHERE id = :online_id');
- $insertCategory->bindValue(':id_off', $category['id_off']);
- $insertCategory->bindValue(':online_id', $category['online_id']);
- $insertCategory->bindValue(':sync', 'yes');
- $insertCategory->execute();
- }
- //CATEGORIAS EXIBIÇÃO
- foreach ($decodedResponse['category_exibition'] as $category_exibition) {
- $insertCategoryExibition = $conn->prepare('UPDATE `category_exibition` SET sync = :sync, id_category_exibition_off = :id_off WHERE id = :online_id');
- $insertCategoryExibition->bindValue(':online_id', $category_exibition['online_id']);
- $insertCategoryExibition->bindValue(':id_off', $category_exibition['id_off']);
- $insertCategoryExibition->bindValue(':sync', 'yes');
- $insertCategoryExibition->execute();
- }
- foreach ($decodedResponse['command'] as $command) {
- $insertCommand = $conn->prepare('UPDATE `command` SET sync = :sync, id_command_off = :id_off WHERE id = :online_id');
- $insertCommand->bindValue(':id_off', $command['id_off']);
- $insertCommand->bindValue(':online_id', $command['online_id']);
- $insertCommand->bindValue(':sync', 'yes');
- $insertCommand->execute();
- }
- foreach ($decodedResponse['config'] as $user) {
- $insertUser = $conn->prepare('UPDATE `config` SET id_config_off = :id_off, sync = :sync WHERE id = :online_id');
- $insertUser->bindValue(':online_id', $user['online_id']);
- $insertUser->bindValue(':id_off', $user['id_off']);
- $insertUser->bindValue(':sync', 'yes');
- $insertUser->execute();
- }
- foreach ($decodedResponse['company_user'] as $user) {
- $insertUser = $conn->prepare('UPDATE `company_user` SET id_company_user_off = :id_off, sync = :sync WHERE id = :online_id');
- $insertUser->bindValue(':online_id', $user['online_id']);
- $insertUser->bindValue(':id_off', $user['id_off']);
- $insertUser->bindValue(':sync', 'yes');
- $insertUser->execute();
- }
- foreach ($decodedResponse['menu'] as $menuType) {
- $insertMenuType = $conn->prepare('UPDATE`menu_type` SET sync = :sync, id_menu_type_off = :id_off WHERE id = :online_id');
- $insertMenuType->bindValue(':online_id', $menuType['online_id']);
- $insertMenuType->bindValue(':id_off', $menuType['id_off']);
- $insertMenuType->bindValue(':sync', 'yes');
- $insertMenuType->execute();
- }
- foreach ($decodedResponse['company_log'] as $log) {
- $insertLog = $conn->prepare('UPDATE `company_log` SET sync = :sync, id_log_off = :id_off WHERE id = :online_id');
- $insertLog->bindValue(':online_id', $log['online_id']);
- $insertLog->bindValue(':id_off', $log['id_off']);
- $insertLog->bindValue(':sync', 'yes');
- $insertLog->execute();
- }
- foreach ($decodedResponse['preference'] as $preference) {
- $insertPreference = $conn->prepare('UPDATE `preference` SET id_preference_off = :id_off, sync = :sync WHERE id = :online_id');
- $insertPreference->bindValue(':online_id', $preference['online_id']);
- $insertPreference->bindValue(':id_off', $preference['id_off']);
- $insertPreference->bindValue(':sync', 'yes');
- $insertPreference->execute();
- }
- foreach ($decodedResponse['preference_category'] as $preference) {
- $insertPreference = $conn->prepare('UPDATE`preference_category` SET sync = :sync, id_preference_category_off = :id_off WHERE id = :online_id');
- $insertPreference->bindValue(':online_id', $preference['online_id']);
- $insertPreference->bindValue(':id_off', $preference['id_off']);
- $insertPreference->bindValue(':sync', 'yes');
- $insertPreference->execute();
- }
- foreach ($decodedResponse['preference_item'] as $preference) {
- $insertPreference = $conn->prepare('UPDATE `preference_item` SET sync = :sync, id_preference_item_off = :id_off WHERE id = :online_id');
- $insertPreference->bindValue(':online_id', $preference['online_id']);
- $insertPreference->bindValue(':id_off', $preference['id_off']);
- $insertPreference->bindValue(':sync', 'yes');
- $insertPreference->execute();
- }
- foreach ($decodedResponse['products'] as $product) {
- $insertProduct = $conn->prepare('UPDATE `product` SET sync = :sync, id_product_off = :id_off WHERE id = :online_id');
- $insertProduct->bindValue(':online_id', $product['online_id']);
- $insertProduct->bindValue(':id_off', $product['id_off']);
- $insertProduct->bindValue(':sync', 'yes');
- $insertProduct->execute();
- }
- foreach ($decodedResponse['product_additionals'] as $product) {
- $insertProduct = $conn->prepare('UPDATE `product_additional` SET sync = :sync, id_product_additional_off = :id_off WHERE id = :online_id');
- $insertProduct->bindValue(':online_id', $product['online_id']);
- $insertProduct->bindValue(':id_off', $product['id_off']);
- $insertProduct->bindValue(':sync', 'yes');
- $insertProduct->execute();
- }
- foreach ($decodedResponse['product_category'] as $product) {
- $insertProduct = $conn->prepare('UPDATE `product_category` SET sync = :sync, id_product_category_off = :id_off WHERE id = :online_id');
- $insertProduct->bindValue(':online_id', $product['online_id']);
- $insertProduct->bindValue(':id_off', $product['id_off']);
- $insertProduct->bindValue(':sync', 'yes');
- $insertProduct->execute();
- }
- //PRODUTOS EXIBIÇÃO
- foreach ($decodedResponse['product_exibition'] as $product_exibition) {
- $insertProductExibition = $conn->prepare('UPDATE `product_exibition` SET sync = :sync, id_product_exibition_off = :id_off WHERE id = :online_id');
- $insertProductExibition->bindValue(':online_id', $product_exibition['online_id']);
- $insertProductExibition->bindValue(':id_off', $product_exibition['id_off']);
- $insertProductExibition->bindValue(':sync', 'yes');
- $insertProductExibition->execute();
- }
- foreach ($decodedResponse['product_image'] as $product_exibition) {
- $insertProductImage = $conn->prepare('UPDATE `product_image` SET sync = :sync, id_product_image_off = :id_off WHERE id = :online_id');
- $insertProductImage->bindValue(':online_id', $product_exibition['online_id']);
- $insertProductImage->bindValue(':id_off', $product_exibition['id_off']);
- $insertProductImage->bindValue(':sync', 'yes');
- $insertProductImage->execute();
- }
- foreach ($decodedResponse['product_preference'] as $product) {
- $productPreference = $conn->prepare('UPDATE `product_preference` SET sync = :sync, id_product_preference_off = :id_off WHERE id = :online_id');
- $productPreference->bindValue(':online_id', $product['online_id']);
- $productPreference->bindValue(':id_off', $product['id_off']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->execute();
- }
- foreach ($decodedResponse['product_types'] as $product) {
- $productPreference = $conn->prepare('UPDATE `product_type` SET sync = :sync, id_product_type_off = :id_off WHERE id = :online_id');
- $productPreference->bindValue(':online_id', $product['online_id']);
- $productPreference->bindValue(':id_off', $product['id_off']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->execute();
- }
- foreach ($decodedResponse['sale_type'] as $sale) {
- $saleType = $conn->prepare('UPDATE `sale_type` SET sync = :sync, id_sale_type_off = :id_off WHERE id = :online_id');
- $saleType->bindValue(':online_id', $sale['online_id']);
- $saleType->bindValue(':id_off', $sale['id_off']);
- $saleType->bindValue(':sync', 'yes');
- $saleType->execute();
- }
- foreach ($decodedResponse['product_sales'] as $product) {
- $productPreference = $conn->prepare('UPDATE `product_sale` SET sync = :sync, id_product_sale_off = :id_off WHERE id = :online_id');
- $productPreference->bindValue(':online_id', $product['online_id']);
- $productPreference->bindValue(':id_off', $product['id_off']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->execute();
- }
- foreach ($decodedResponse['table'] as $table) {
- $insertTable = $conn->prepare('UPDATE `table` SET sync = :sync, id_table_off = :id_off WHERE id = :online_id');
- $insertTable->bindValue(':online_id', $table['online_id']);
- $insertTable->bindValue(':id_off', $table['id_off']);
- $insertTable->bindValue(':sync', 'yes');
- $insertTable->execute();
- }
- foreach ($decodedResponse['command_table'] as $command_table) {
- $insertCommandTable = $conn->prepare('UPDATE `command_table` SET sync = :sync, id_command_table_off = :id_off WHERE id = :online_id');
- $insertCommandTable->bindValue(':online_id', $command_table['online_id']);
- $insertCommandTable->bindValue(':id_off', $command_table['id_off']);
- $insertCommandTable->bindValue(':sync', 'yes');
- $insertCommandTable->execute();
- }
- foreach ($decodedResponse['tag'] as $table) {
- $insertTable = $conn->prepare('UPDATE `tag` SET sync = :sync WHERE id = :online_id');
- $insertTable->bindValue(':online_id', $table['online_id']);
- $insertTable->bindValue(':sync', 'yes');
- $insertTable->execute();
- }
- foreach ($decodedResponse['product_tags'] as $product) {
- $productPreference = $conn->prepare('UPDATE `product_tag` SET sync = :sync, id_product_tag_off = :id_off WHERE id = :online_id');
- $productPreference->bindValue(':online_id', $product['online_id']);
- $productPreference->bindValue(':id_off', $product['id_off']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->execute();
- }
- foreach ($decodedResponse['target'] as $table) {
- $insertTable = $conn->prepare('UPDATE `target_audience` SET sync = :sync WHERE id = :online_id');
- $insertTable->bindValue(':online_id', $table['online_id']);
- $insertTable->bindValue(':sync', 'yes');
- $insertTable->execute();
- }
- foreach ($decodedResponse['combo'] as $combo) {
- $insertCombo = $conn->prepare('UPDATE `combo` SET sync = :sync, id_combo_off = :id_off WHERE id = :online_id');
- $insertCombo->bindValue(':online_id', $combo['online_id']);
- $insertCombo->bindValue(':id_off', $combo['id_off']);
- $insertCombo->bindValue(':sync', 'yes');
- $insertCombo->execute();
- }
- foreach ($decodedResponse['combo_group'] as $combo_group) {
- $insertComboGroup = $conn->prepare('UPDATE `combo_group` SET sync = :sync, id_combo_group_off = :id_off WHERE id = :online_id');
- $insertComboGroup->bindValue(':online_id', $combo_group['online_id']);
- $insertComboGroup->bindValue(':id_off', $combo_group['id_off']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->execute();
- }
- foreach ($decodedResponse['combo_group_item'] as $combo_group) {
- $insertComboGroup = $conn->prepare('UPDATE `combo_group_item` SET sync = :sync, id_combo_group_item_off = :id_off WHERE id = :online_id');
- $insertComboGroup->bindValue(':online_id', $combo_group['online_id']);
- $insertComboGroup->bindValue(':id_off', $combo_group['id_off']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->execute();
- }
- foreach ($decodedResponse['combo_type'] as $combo_group) {
- $insertComboGroup = $conn->prepare('UPDATE `combo_type` SET sync = :sync, id_combo_type_off = :id_off WHERE id = :online_id');
- $insertComboGroup->bindValue(':online_id', $combo_group['online_id']);
- $insertComboGroup->bindValue(':id_off', $combo_group['id_off']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->execute();
- }
- foreach ($decodedResponse['combo_image'] as $combo_group) {
- $insertComboGroup = $conn->prepare('UPDATE `combo_image` SET sync = :sync, id_combo_image_off = :id_off WHERE id = :online_id');
- $insertComboGroup->bindValue(':online_id', $combo_group['online_id']);
- $insertComboGroup->bindValue(':id_off', $combo_group['id_off']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->execute();
- }
- foreach ($decodedResponse['combo_exibition'] as $combo_group) {
- $insertComboGroup = $conn->prepare('UPDATE `combo_exibition` SET sync = :sync, id_combo_exibition_off = :id_off WHERE id = :online_id');
- $insertComboGroup->bindValue(':online_id', $combo_group['online_id']);
- $insertComboGroup->bindValue(':id_off', $combo_group['id_off']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->execute();
- }
- //INSERE AS CAMPANHAS
- foreach ($decodedResponse['campaign'] as $campaign) {
- $insertCampaign = $conn->prepare('UPDATE `campaign` SET sync = :sync WHERE id = :online_id');
- $insertCampaign->bindValue(':online_id', $campaign['online_id']);
- $insertCampaign->bindValue(':sync', 'yes');
- $insertCampaign->execute();
- }
- //INSERE AS CAMPANHAS NAS EMPRESAS
- foreach ($decodedResponse['campaign_company'] as $campaign) {
- $insertCampaign = $conn->prepare('UPDATE `campaign_company` SET sync = :sync WHERE id = :online_id');
- $insertCampaign->bindValue(':online_id', $campaign['online_id']);
- $insertCampaign->bindValue(':sync', 'yes');
- $insertCampaign->execute();
- }
- //INSERE AS CAMPANHAS DAS EMPRESAS
- foreach ($decodedResponse['restaurant_campaign'] as $campaign) {
- $insertCampaign = $conn->prepare('UPDATE `restaurant_campaign` SET sync = :sync, id_restaurant_campaign_off = :id_off WHERE id = :online_id');
- $insertCampaign->bindValue(':online_id', $campaign['online_id']);
- $insertCampaign->bindValue(':id_off', $campaign['id_off']);
- $insertCampaign->bindValue(':sync', 'yes');
- $insertCampaign->execute();
- }
- //INSERE AS CAMPANHAS DAS EMPRESAS
- foreach ($decodedResponse['restaurant_campaign_product'] as $campaign) {
- $insertCampaign = $conn->prepare('UPDATE `restaurant_campaign_product` SET sync = :sync, id_restaurant_campaign_product_off = :id_off WHERE id = :online_id');
- $insertCampaign->bindValue(':online_id', $campaign['online_id']);
- $insertCampaign->bindValue(':id_off', $campaign['id_off']);
- $insertCampaign->bindValue(':sync', 'yes');
- $insertCampaign->execute();
- }
- $conn->commit();
- $list['error'] = 'false';
- return $list;
- }
- catch (Exception $e) {
- $list['error'] = 'true';
- $conn->rollBack();
- return $list;
- }
- }
- /**
- * Método utilizado para inserir ou atualizar dados da off na online
- * @param [type] $decodedResponse [description]
- * @return [type] [description]
- */
- public function insertIntoOnline($decodedResponse)
- {
- $conn = DatabaseUtils::getDB();
- $conn->beginTransaction();
- try {
- foreach ($decodedResponse['evaluation'] as $avaliation) {
- if ($avaliation['sync'] == 'never') {
- $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)');
- $insertEvaluation->bindValue(':id_company', $avaliation['id_company']);
- $insertEvaluation->bindValue(':id', $avaliation['id']);
- $insertEvaluation->bindValue(':name', $avaliation['name']);
- $insertEvaluation->bindValue(':drink', $avaliation['drink']);
- $insertEvaluation->bindValue(':food', $avaliation['food']);
- $insertEvaluation->bindValue(':music', $avaliation['music']);
- $insertEvaluation->bindValue(':environment', $avaliation['environment']);
- $insertEvaluation->bindValue(':attendance', $avaliation['attendance']);
- $insertEvaluation->bindValue(':description', $avaliation['description']);
- $insertEvaluation->bindValue(':email', $avaliation['email']);
- $insertEvaluation->bindValue(':sync', 'yes');
- $insertEvaluation->bindValue(':deleted_at', $avaliation['deleted_at']);
- $insertEvaluation->bindValue(':created_at', $avaliation['created_at']);
- $insertEvaluation->bindValue(':updated_at', $avaliation['updated_at']);
- $insertEvaluation->execute();
- } else {
- $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');
- $insertEvaluation->bindValue(':id_company', $avaliation['id_company']);
- $insertEvaluation->bindValue(':id', $avaliation['id']);
- $insertEvaluation->bindValue(':name', $avaliation['name']);
- $insertEvaluation->bindValue(':drink', $avaliation['drink']);
- $insertEvaluation->bindValue(':food', $avaliation['food']);
- $insertEvaluation->bindValue(':music', $avaliation['music']);
- $insertEvaluation->bindValue(':environment', $avaliation['environment']);
- $insertEvaluation->bindValue(':attendance', $avaliation['attendance']);
- $insertEvaluation->bindValue(':description', $avaliation['description']);
- $insertEvaluation->bindValue(':email', $avaliation['email']);
- $insertEvaluation->bindValue(':sync', 'yes');
- $insertEvaluation->bindValue(':deleted_at', $avaliation['deleted_at']);
- $insertEvaluation->bindValue(':created_at', $avaliation['created_at']);
- $insertEvaluation->bindValue(':updated_at', $avaliation['updated_at']);
- $insertEvaluation->execute();
- }
- }
- foreach ($decodedResponse['additionals'] as $additional) {
- if ($additional['sync'] == 'never') {
- $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)');
- $insertAdditional->bindValue(':id_company', $additional['id_company']);
- $insertAdditional->bindValue(':id_additional_off', $additional['id']);
- $insertAdditional->bindValue(':name', $additional['name']);
- $insertAdditional->bindValue(':description', $additional['description']);
- $insertAdditional->bindValue(':price', $additional['price']);
- $insertAdditional->bindValue(':image', $additional['image']);
- $insertAdditional->bindValue(':status', $additional['status']);
- $insertAdditional->bindValue(':sync', 'yes');
- $insertAdditional->bindValue(':deleted_at', $additional['deleted_at']);
- $insertAdditional->bindValue(':created_at', $additional['created_at']);
- $insertAdditional->bindValue(':updated_at', $additional['updated_at']);
- $insertAdditional->execute();
- $arrayAdditional['id_off'] = $conn->lastInsertId();
- $arrayAdditional['online_id'] = $additional['id'];
- $arrayAdditionalOnlineId[] = $additional['id'];
- $arrayAdditionalOffId[] = $arrayAdditional['id_off'];
- $objectAddtional[] = $arrayAdditional;
- } else {
- $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');
- $insertAdditional->bindValue(':id_company', $additional['id_company']);
- $insertAdditional->bindValue(':id_additional_off', $additional['id']);
- $insertAdditional->bindValue(':name', $additional['name']);
- $insertAdditional->bindValue(':description', $additional['description']);
- $insertAdditional->bindValue(':price', $additional['price']);
- $insertAdditional->bindValue(':image', $additional['image']);
- $insertAdditional->bindValue(':status', $additional['status']);
- $insertAdditional->bindValue(':sync', 'yes');
- $insertAdditional->bindValue(':deleted_at', $additional['deleted_at']);
- $insertAdditional->bindValue(':created_at', $additional['created_at']);
- $insertAdditional->bindValue(':updated_at', $additional['updated_at']);
- $insertAdditional->execute();
- $arrayAdditional['id_off'] = $conn->lastInsertId();
- $arrayAdditional['online_id'] = $additional['id'];
- $arrayAdditionalOnlineId[] = $additional['id'];
- $arrayAdditionalOffId[] = $arrayAdditional['id_off'];
- $objectAddtional[] = $arrayAdditional;
- }
- if (!empty($additional['image'])) {
- $this->downloadImage($additional['image']);
- }
- }
- foreach ($decodedResponse['category'] as $category) {
- if ($category['sync'] == 'never') {
- $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)');
- $insertCategory->bindValue(':id_company', $category['id_company']);
- $insertCategory->bindValue(':id_category_off', $category['id']);
- $insertCategory->bindValue(':name', $category['name']);
- $insertCategory->bindValue(':image', $category['image']);
- $insertCategory->bindValue(':status', $category['status']);
- $insertCategory->bindValue(':order', $category['order']);
- $insertCategory->bindValue(':sync', 'yes');
- $insertCategory->bindValue(':deleted_at', $category['deleted_at']);
- $insertCategory->bindValue(':created_at', $category['created_at']);
- $insertCategory->bindValue(':updated_at', $category['updated_at']);
- $insertCategory->execute();
- // $arrayCategory['id_off'] = $conn->lastInsertId();
- // $arrayCategory['online_id'] = $category['id'];
- // $arrayCategoryOnlineId[] = $category['id'];
- // $categoryOnlineId = $category['id'];
- // $categoryoffId = $arrayCategory['id_off'];
- // $arrayCategoryOffId[] = $arrayCategory['id_off'] ;
- // $objectCategory[] = $arrayCategory;
- } else {
- $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');
- $insertCategory->bindValue(':id_company', $category['id_company']);
- $insertCategory->bindValue(':id_category_off', $category['id']);
- $insertCategory->bindValue(':name', $category['name']);
- $insertCategory->bindValue(':image', $category['image']);
- $insertCategory->bindValue(':status', $category['status']);
- $insertCategory->bindValue(':order', $category['order']);
- $insertCategory->bindValue(':sync', 'yes');
- $insertCategory->bindValue(':deleted_at', $category['deleted_at']);
- $insertCategory->bindValue(':created_at', $category['created_at']);
- $insertCategory->bindValue(':updated_at', $category['updated_at']);
- $insertCategory->execute();
- $arrayCategory['id_off'] = $conn->lastInsertId();
- $arrayCategory['online_id'] = $category['id'];
- $arrayCategoryOnlineId[] = $category['id'];
- $categoryOnlineId = $category['id'];
- $categoryoffId = $arrayCategory['id_off'];
- $arrayCategoryOffId[] = $arrayCategory['id_off'];
- $objectCategory[] = $arrayCategory;
- }
- if (!empty($category['image'])) {
- $this->downloadImage($category['image']);
- }
- }
- foreach ($decodedResponse['category_exibition'] as $category_exibition) {
- $selectCategory = $conn->prepare('SELECT id from category where id_company = :id_company and id_category_off = :id_category_off');
- $selectCategory->bindValue(':id_company', $category_exibition['id_company']);
- $selectCategory->bindValue(':id_category_off', $category_exibition['id_category']);
- $selectCategory->execute();
- $categoryId = $selectCategory->fetch(PDO::FETCH_ASSOC);
- if ($category_exibition['sync'] == 'never') {
- $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)');
- $insertCategoryExibition->bindValue(':id_company', $category_exibition['id_company']);
- $insertCategoryExibition->bindValue(':id_category_exibition_off', $category_exibition['id']);
- $insertCategoryExibition->bindValue(':id_category', $categoryId['id']);
- $insertCategoryExibition->bindValue(':day', $category_exibition['day']);
- $insertCategoryExibition->bindValue(':at', $category_exibition['at']);
- $insertCategoryExibition->bindValue(':to', $category_exibition['to']);
- $insertCategoryExibition->bindValue(':display', $category_exibition['display']);
- $insertCategoryExibition->bindValue(':sync', 'yes');
- $insertCategoryExibition->bindValue(':deleted_at', $category_exibition['deleted_at']);
- $insertCategoryExibition->bindValue(':created_at', $category_exibition['created_at']);
- $insertCategoryExibition->bindValue(':updated_at', $category_exibition['updated_at']);
- $insertCategoryExibition->execute();
- // $arrayCategory['id_off'] = $conn->lastInsertId();
- // $arrayCategory['online_id'] = $category_exibition['id'];
- // $objectCategoryExibition[] = $arrayCategory;
- } else {
- $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');
- $insertCategoryExibition->bindValue(':id_company', $category_exibition['id_company']);
- $insertCategoryExibition->bindValue(':id_category_off', $categoryId['id']);
- $insertCategoryExibition->bindValue(':id_category_exibition_off', $category_exibition['id']);
- $insertCategoryExibition->bindValue(':day', $category_exibition['day']);
- $insertCategoryExibition->bindValue(':at', $category_exibition['at']);
- $insertCategoryExibition->bindValue(':to', $category_exibition['to']);
- $insertCategoryExibition->bindValue(':display', $category_exibition['display']);
- $insertCategoryExibition->bindValue(':sync', 'yes');
- $insertCategoryExibition->bindValue(':deleted_at', $category_exibition['deleted_at']);
- $insertCategoryExibition->bindValue(':created_at', $category_exibition['created_at']);
- $insertCategoryExibition->bindValue(':updated_at', $category_exibition['updated_at']);
- $insertCategoryExibition->execute();
- // $arrayCategory['id_off'] = $conn->lastInsertId();
- // $arrayCategory['online_id'] = $category_exibition['id'];
- // $objectCategoryExibition[] = $arrayCategory;
- }
- }
- foreach ($decodedResponse['company'] as $company) {
- $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');
- $insertCompany->bindValue(':id', $company['id']);
- $insertCompany->bindValue(':cnpj', $company['cnpj']);
- $insertCompany->bindValue(':ie', $company['ie']);
- $insertCompany->bindValue(':trading_name', $company['trading_name']);
- $insertCompany->bindValue(':fantasy_name', $company['fantasy_name']);
- $insertCompany->bindValue(':plan', $company['plan']);
- $insertCompany->bindValue(':license', $company['license']);
- $insertCompany->bindValue(':address', $company['address']);
- $insertCompany->bindValue(':blocked', $company['blocked']);
- $insertCompany->bindValue(':sync', 'yes');
- $insertCompany->bindValue(':deleted_at', $company['deleted_at']);
- $insertCompany->bindValue(':created_at', $company['created_at']);
- $insertCompany->bindValue(':updated_at', $company['updated_at']);
- $insertCompany->execute();
- }
- foreach ($decodedResponse['command'] as $command) {
- if ($command['sync'] == 'never') {
- $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)');
- $insertCommand->bindValue(':id_company', $command['id_company']);
- $insertCommand->bindValue(':id', $command['id']);
- $insertCommand->bindValue(':opening_at', $command['opening_at']);
- $insertCommand->bindValue(':total_value', $command['total_value']);
- $insertCommand->bindValue(':closing_at', $command['closing_at']);
- $insertCommand->bindValue(':numberC', $command['number']);
- $insertCommand->bindValue(':active', $command['active']);
- $insertCommand->bindValue(':sync', 'yes');
- $insertCommand->bindValue(':deleted_at', $command['deleted_at']);
- $insertCommand->bindValue(':created_at', $command['created_at']);
- $insertCommand->bindValue(':updated_at', $command['updated_at']);
- $insertCommand->execute();
- // $arrayCategory['id_off'] = $conn->lastInsertId();
- // $arrayCategory['online_id'] = $command['id'];
- // $objectCommand[] = $arrayCategory;
- } else {
- $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');
- $insertCommand->bindValue(':id_company', $command['id_company']);
- $insertCommand->bindValue(':id_command_off', $command['id']);
- $insertCommand->bindValue(':opening_at', $command['opening_at']);
- $insertCommand->bindValue(':total_value', $command['total_value']);
- $insertCommand->bindValue(':closing_at', $command['closing_at']);
- $insertCommand->bindValue(':numberC', $command['number']);
- $insertCommand->bindValue(':active', $command['active']);
- $insertCommand->bindValue(':sync', 'yes');
- $insertCommand->bindValue(':deleted_at', $command['deleted_at']);
- $insertCommand->bindValue(':created_at', $command['created_at']);
- $insertCommand->bindValue(':updated_at', $command['updated_at']);
- $insertCommand->execute();
- // $arrayCategory['id_off'] = $conn->lastInsertId();
- // $arrayCategory['online_id'] = $command['id'];
- // $objectCommand[] = $arrayCategory;
- }
- }
- foreach ($decodedResponse['company_user'] as $user) {
- if ($user['sync'] == 'never') {
- $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)');
- $insertUser->bindValue(':id_company', $user['id_company']);
- $insertUser->bindValue(':id_company_user_off', $user['id']);
- $insertUser->bindValue(':name', $user['name']);
- $insertUser->bindValue(':photo', $user['photo']);
- $insertUser->bindValue(':user', $user['user']);
- $insertUser->bindValue(':password', $user['password']);
- $insertUser->bindValue(':qr_password', $user['qr_password']);
- $insertUser->bindValue(':access_level', $user['access_level']);
- $insertUser->bindValue(':sync', 'yes');
- $insertUser->bindValue(':deleted_at', $user['deleted_at']);
- $insertUser->bindValue(':created_at', $user['created_at']);
- $insertUser->bindValue(':updated_at', $user['updated_at']);
- $insertUser->execute();
- // $arrayUser['id_off'] = $conn->lastInsertId();
- // $userOnlineId = $user['id'];
- // $userOffId = $arrayUser['id_off'];
- // $arrayUser['online_id'] = $user['id'];
- // $objUser[] = $arrayUser;
- } else {
- $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');
- $insertUser->bindValue(':id_company', $user['id_company']);
- $insertUser->bindValue(':id_company_user_off', $user['id']);
- $insertUser->bindValue(':name', $user['name']);
- $insertUser->bindValue(':photo', $user['photo']);
- $insertUser->bindValue(':qr_password', $user['qr_password']);
- $insertUser->bindValue(':user', $user['user']);
- $insertUser->bindValue(':password', $user['password']);
- $insertUser->bindValue(':access_level', $user['access_level']);
- $insertUser->bindValue(':sync', 'yes');
- $insertUser->bindValue(':deleted_at', $user['deleted_at']);
- $insertUser->bindValue(':created_at', $user['created_at']);
- $insertUser->bindValue(':updated_at', $user['updated_at']);
- $insertUser->execute();
- // $arrayUser['id_off'] = $conn->lastInsertId();
- // $userOnlineId = $user['id'];
- // $userOffId = $arrayUser['id_off'];
- // $arrayUser['online_id'] = $user['id'];
- // $objUser[] = $arrayUser;
- }
- if (!empty($user['photo'])) {
- $this->downloadImage($user['photo']);
- }
- }
- foreach ($decodedResponse['company_log'] as $log) {
- $selectUser = $conn->prepare('SELECT id from company_user where id_company = :id_company and id_company_user_off = :id_company_user_off');
- $selectUser->bindValue(':id_company', $log['id_company']);
- $selectUser->bindValue(':id_company_user_off', $log['id_user']);
- $selectUser->execute();
- $userId = $selectUser->fetch(PDO::FETCH_ASSOC);
- $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)');
- $insertLog->bindValue(':id_company', $log['id_company']);
- $insertLog->bindValue(':id_log_off', $log['id']);
- $insertLog->bindValue(':id_user', $userId['id']);
- $insertLog->bindValue(':page', $log['page']);
- $insertLog->bindValue(':message', $log['message']);
- $insertLog->bindValue(':subject', $log['subject']);
- $insertLog->bindValue(':sync', 'yes');
- $insertLog->bindValue(':deleted_at', $log['deleted_at']);
- $insertLog->bindValue(':created_at', $log['created_at']);
- $insertLog->bindValue(':updated_at', $log['updated_at']);
- $insertLog->execute();
- // $arrayCategory['id_off'] = $conn->lastInsertId();
- // $arrayCategory['online_id'] = $log['id'];
- // $objLog[] = $arrayCategory;
- }
- foreach ($decodedResponse['menu'] as $menuType) {
- if ($menuType['sync'] == 'never') {
- $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)');
- $insertMenuType->bindValue(':id_menu_type_off', $menuType['id']);
- $insertMenuType->bindValue(':id_company', $menuType['id_company']);
- $insertMenuType->bindValue(':name', $menuType['name']);
- $insertMenuType->bindValue(':description', $menuType['description']);
- $insertMenuType->bindValue(':status', $menuType['status']);
- $insertMenuType->bindValue(':sync', 'yes');
- $insertMenuType->bindValue(':deleted_at', $menuType['deleted_at']);
- $insertMenuType->bindValue(':created_at', $menuType['created_at']);
- $insertMenuType->bindValue(':updated_at', $menuType['updated_at']);
- $insertMenuType->execute();
- // $arrayMenu['id_off'] = $conn->lastInsertId();
- // $arrayMenu['online_id'] = $menuType['id'];
- // $objMenu[] = $arrayMenu;
- } else {
- $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');
- $insertMenuType->bindValue(':id_menu_type_off', $menuType['id']);
- $insertMenuType->bindValue(':id_company', $menuType['id_company']);
- $insertMenuType->bindValue(':name', $menuType['name']);
- $insertMenuType->bindValue(':description', $menuType['description']);
- $insertMenuType->bindValue(':status', $menuType['status']);
- $insertMenuType->bindValue(':sync', 'yes');
- $insertMenuType->bindValue(':deleted_at', $menuType['deleted_at']);
- $insertMenuType->bindValue(':created_at', $menuType['created_at']);
- $insertMenuType->bindValue(':updated_at', $menuType['updated_at']);
- $insertMenuType->execute();
- }
- }
- foreach ($decodedResponse['preference'] as $preference) {
- if ($preference['sync'] == 'never') {
- $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)');
- $insertPreference->bindValue(':id_company', $preference['id_company']);
- $insertPreference->bindValue(':id_preference_off', $preference['id']);
- $insertPreference->bindValue(':name', $preference['name']);
- $insertPreference->bindValue(':description', $preference['description']);
- $insertPreference->bindValue(':display', $preference['display']);
- $insertPreference->bindValue(':multiple', $preference['multiple']);
- $insertPreference->bindValue(':order', $preference['order']);
- $insertPreference->bindValue(':sync', 'yes');
- $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
- $insertPreference->bindValue(':created_at', $preference['created_at']);
- $insertPreference->bindValue(':updated_at', $preference['updated_at']);
- $insertPreference->execute();
- // $preferenceArray['id_off'] = $conn->lastInsertId();
- // $preferenceId = $preferenceArray['id_off'];
- // $preferenceArray['online_id'] = $preference['id'];
- // $preferenceOnlineId = $preference['id'];
- // $arrayPreferenceOffline[] = $preferenceArray['id_off'];
- // $arrayPreferenceOnline[] = $preference['id'];
- // $objPreference[] = $preferenceArray;
- } else {
- $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');
- $insertPreference->bindValue(':id_preference_off', $preference['id']);
- $insertPreference->bindValue(':id_company', $preference['id_company']);
- $insertPreference->bindValue(':name', $preference['name']);
- $insertPreference->bindValue(':description', $preference['description']);
- $insertPreference->bindValue(':display', $preference['display']);
- $insertPreference->bindValue(':multiple', $preference['multiple']);
- $insertPreference->bindValue(':order', $preference['order']);
- $insertPreference->bindValue(':sync', 'yes');
- $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
- $insertPreference->bindValue(':created_at', $preference['created_at']);
- $insertPreference->bindValue(':updated_at', $preference['updated_at']);
- $insertPreference->execute();
- }
- //items de uma preferencia
- }
- foreach ($decodedResponse['preference_category'] as $preference) {
- $selectCategory = $conn->prepare('SELECT id from category where id_company = :id_company and id_category_off = :id_category_off');
- $selectCategory->bindValue(':id_company', $preference['id_company']);
- $selectCategory->bindValue(':id_category_off', $preference['id_category']);
- $selectCategory->execute();
- $categoryId = $selectCategory->fetch(PDO::FETCH_ASSOC);
- $selectPreference = $conn->prepare('SELECT id from preference where id_company = :id_company and id_preference_off = :id_preference_off');
- $selectPreference->bindValue(':id_company', $preference['id_company']);
- $selectPreference->bindValue(':id_preference_off', $preference['id_preference']);
- $selectPreference->execute();
- $preferenceId = $selectPreference->fetch(PDO::FETCH_ASSOC);
- if ($preference['sync'] == 'never') {
- $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)');
- $insertPreference->bindValue(':id_company', $preference['id_company']);
- $insertPreference->bindValue(':id_preference_category_off', $preference['id']);
- $insertPreference->bindValue(':id_category', $categoryId['id']);
- $insertPreference->bindValue(':id_preference', $preferenceId['id']);
- $insertPreference->bindValue(':sync', 'yes');
- $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
- $insertPreference->bindValue(':created_at', $preference['created_at']);
- $insertPreference->bindValue(':updated_at', $preference['updated_at']);
- $insertPreference->execute();
- // $preferenceArray['id_off'] = $conn->lastInsertId();
- // $preferenceArray['online_id'] = $preference['id'];
- // $objPreferenceCategory[] = $preferenceArray;
- } else {
- $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');
- $insertPreference->bindValue(':id_preference_category_off', $preference['id']);
- $insertPreference->bindValue(':id_company', $preference['id_company']);
- $insertPreference->bindValue(':id_category', $categoryId['id']);
- $insertPreference->bindValue(':id_preference', $preferenceId['id']);
- $insertPreference->bindValue(':sync', 'yes');
- $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
- $insertPreference->bindValue(':created_at', $preference['created_at']);
- $insertPreference->bindValue(':updated_at', $preference['updated_at']);
- $insertPreference->execute();
- }
- }
- foreach ($decodedResponse['preference_item'] as $preference) {
- $selectPreference = $conn->prepare('SELECT id from preference where id_company = :id_company and id_preference_off = :id_preference_off');
- $selectPreference->bindValue(':id_company', $preference['id_company']);
- $selectPreference->bindValue(':id_preference_off', $preference['id_preference']);
- $selectPreference->execute();
- $preferenceId = $selectPreference->fetch(PDO::FETCH_ASSOC);
- if ($preference['sync'] == 'never') {
- $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)');
- $insertPreference->bindValue(':id_company', $preference['id_company']);
- $insertPreference->bindValue(':id_preference', $preferenceId['id']);
- $insertPreference->bindValue(':id_preference_item_off', $preference['id']);
- $insertPreference->bindValue(':name', $preference['name']);
- $insertPreference->bindValue(':description', $preference['description']);
- $insertPreference->bindValue(':order', $preference['order']);
- $insertPreference->bindValue(':status', $preference['status']);
- $insertPreference->bindValue(':sync', 'yes');
- $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
- $insertPreference->bindValue(':created_at', $preference['created_at']);
- $insertPreference->bindValue(':updated_at', $preference['updated_at']);
- $insertPreference->execute();
- // $preferenceArray['id_off'] = $conn->lastInsertId();
- // $preferenceArray['online_id'] = $preference['id'];
- // $objPreferenceItem[] = $preferenceArray;
- } else {
- $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');
- $insertPreference->bindValue(':id_preference_item_off', $preference['id']);
- $insertPreference->bindValue(':id_company', $preference['id_company']);
- $insertPreference->bindValue(':id_preference', $preferenceId['id']);
- $insertPreference->bindValue(':name', $preference['name']);
- $insertPreference->bindValue(':description', $preference['description']);
- $insertPreference->bindValue(':order', $preference['order']);
- $insertPreference->bindValue(':status', $preference['status']);
- $insertPreference->bindValue(':sync', 'yes');
- $insertPreference->bindValue(':deleted_at', $preference['deleted_at']);
- $insertPreference->bindValue(':created_at', $preference['created_at']);
- $insertPreference->bindValue(':updated_at', $preference['updated_at']);
- $insertPreference->execute();
- }
- }
- foreach ($decodedResponse['sale_type'] as $sale) {
- if ($sale['sync'] == 'never') {
- $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)');
- $saleType->bindValue(':id_company', $sale['id_company']);
- $saleType->bindValue(':id_sale_type_off', $sale['id']);
- $saleType->bindValue(':name', $sale['name']);
- $saleType->bindValue(':status', $sale['status']);
- $saleType->bindValue(':description', $sale['description']);
- $saleType->bindValue(':sync', 'yes');
- $saleType->bindValue(':deleted_at', $sale['deleted_at']);
- $saleType->bindValue(':created_at', $sale['created_at']);
- $saleType->bindValue(':updated_at', $sale['updated_at']);
- $saleType->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $sale['id'];
- // $arraySalesOnline[] = $sale['id'];
- // $arraySalesOffline[] = $productArray['id_off'];
- // $objSale[] = $productArray;
- } else {
- $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');
- $saleType->bindValue(':id_sale_type_off', $sale['id']);
- $saleType->bindValue(':id_company', $sale['id_company']);
- $saleType->bindValue(':name', $sale['name']);
- $saleType->bindValue(':status', $sale['status']);
- $saleType->bindValue(':description', $sale['description']);
- $saleType->bindValue(':sync', 'yes');
- $saleType->bindValue(':deleted_at', $sale['deleted_at']);
- $saleType->bindValue(':created_at', $sale['created_at']);
- $saleType->bindValue(':updated_at', $sale['updated_at']);
- $saleType->execute();
- }
- }
- foreach ($decodedResponse['products'] as $product) {
- if ($product['sync'] == 'never') {
- $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)');
- $insertProduct->bindValue(':id_company', $product['id_company']);
- $insertProduct->bindValue(':id_product_off', $product['id']);
- $insertProduct->bindValue(':name', $product['name']);
- $insertProduct->bindValue(':description', $product['description']);
- $insertProduct->bindValue(':order', $product['order']);
- $insertProduct->bindValue(':status', $product['status']);
- $insertProduct->bindValue(':id_system', $product['id_system']);
- $insertProduct->bindValue(':all_you_can_eat', $product['all_you_can_eat']);
- $insertProduct->bindValue(':sync', 'yes');
- $insertProduct->bindValue(':deleted_at', $product['deleted_at']);
- $insertProduct->bindValue(':created_at', $product['created_at']);
- $insertProduct->bindValue(':updated_at', $product['updated_at']);
- $insertProduct->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productId = $productArray['id_off'];
- // $productArray['online_id'] = $product['id'];
- // $productOnlineId = $product['id'];
- // $arrayProductOnline[] = $productOnlineId;
- // $arrayProductOff[] = $productId;
- // $objProducts[] = $productArray;
- } else {
- $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');
- $insertProduct->bindValue(':id', $product['id']);
- $insertProduct->bindValue(':id_company', $product['id_company']);
- $insertProduct->bindValue(':name', $product['name']);
- $insertProduct->bindValue(':description', $product['description']);
- $insertProduct->bindValue(':order', $product['order']);
- $insertProduct->bindValue(':status', $product['status']);
- $insertProduct->bindValue(':id_system', $product['id_system']);
- $insertProduct->bindValue(':all_you_can_eat', $product['all_you_can_eat']);
- $insertProduct->bindValue(':sync', 'yes');
- $insertProduct->bindValue(':deleted_at', $product['deleted_at']);
- $insertProduct->bindValue(':created_at', $product['created_at']);
- $insertProduct->bindValue(':updated_at', $product['updated_at']);
- $insertProduct->execute();
- }
- }
- foreach ($decodedResponse['product_additionals'] as $product_additional) {
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
- $selectProduct->bindValue(':id_company', $product_additional['id_company']);
- $selectProduct->bindValue(':id_product_off', $product_additional['id_product']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- $selectAdditional = $conn->prepare('SELECT id from additional where id_company = :id_company and id_additional_off = :id_additional_off');
- $selectAdditional->bindValue(':id_company', $product_additional['id_company']);
- $selectAdditional->bindValue(':id_additional_off', $product_additional['id_additional']);
- $selectAdditional->execute();
- $additionalId = $selectAdditional->fetch(PDO::FETCH_ASSOC);
- if ($product_additional['sync'] == 'never') {
- $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)');
- $insertProduct->bindValue(':id_company', $product_additional['id_company']);
- $insertProduct->bindValue(':id_product_additional_off', $product_additional['id']);
- $insertProduct->bindValue(':id_additional', $additionalId['id']);
- $insertProduct->bindValue(':id_product', $productId['id']);
- $insertProduct->bindValue(':order', $product_additional['order']);
- $insertProduct->bindValue(':status', $product_additional['status']);
- $insertProduct->bindValue(':sync', 'yes');
- $insertProduct->bindValue(':deleted_at', $product_additional['deleted_at']);
- $insertProduct->bindValue(':created_at', $product_additional['created_at']);
- $insertProduct->bindValue(':updated_at', $product_additional['updated_at']);
- $insertProduct->execute();
- // $productAdditionalArray['id_off'] = $conn->lastInsertId();
- // $productAdditionalArray['online_id'] = $product_additional['id'];
- // $objProductsAdditionals[] = $productAdditionalArray;
- } else {
- $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');
- $insertProduct->bindValue(':id', $product_additional['id']);
- $insertProduct->bindValue(':id_company', $product_additional['id_company']);
- $insertProduct->bindValue(':id_additional', $additionalId['id']);
- $insertProduct->bindValue(':id_product', $productId['id']);
- $insertProduct->bindValue(':order', $product_additional['order']);
- $insertProduct->bindValue(':status', $product_additional['status']);
- $insertProduct->bindValue(':sync', 'yes');
- $insertProduct->bindValue(':deleted_at', $product_additional['deleted_at']);
- $insertProduct->bindValue(':created_at', $product_additional['created_at']);
- $insertProduct->bindValue(':updated_at', $product_additional['updated_at']);
- $insertProduct->execute();
- }
- }
- foreach ($decodedResponse['product_category'] as $product) {
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
- $selectProduct->bindValue(':id_company', $product['id_company']);
- $selectProduct->bindValue(':id_product_off', $product['id_product']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- $selectCategory = $conn->prepare('SELECT id from category where id_company = :id_company and id_category_off = :id_category_off');
- $selectCategory->bindValue(':id_company', $product['id_company']);
- $selectCategory->bindValue(':id_category_off', $product['id_category']);
- $selectCategory->execute();
- $categoryId = $selectCategory->fetch(PDO::FETCH_ASSOC);
- if ($product['sync'] == 'never') {
- $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)');
- $insertProduct->bindValue(':id_product_category_off', $product['id']);
- $insertProduct->bindValue(':id_company', $product['id_company']);
- $insertProduct->bindValue(':id_category', $categoryId['id']);
- $insertProduct->bindValue(':id_product', $productId['id']);
- $insertProduct->bindValue(':sync', 'yes');
- $insertProduct->bindValue(':deleted_at', $product['deleted_at']);
- $insertProduct->bindValue(':created_at', $product['created_at']);
- $insertProduct->bindValue(':updated_at', $product['updated_at']);
- $insertProduct->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $product['id'];
- // $objProductsCategory[] = $productArray;
- } else {
- $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');
- $insertProduct->bindValue(':id', $product['id']);
- $insertProduct->bindValue(':id_company', $product['id_company']);
- $insertProduct->bindValue(':id_category', $categoryId['id']);
- $insertProduct->bindValue(':id_product', $productId['id']);
- $insertProduct->bindValue(':sync', 'yes');
- $insertProduct->bindValue(':deleted_at', $product['deleted_at']);
- $insertProduct->bindValue(':created_at', $product['created_at']);
- $insertProduct->bindValue(':updated_at', $product['updated_at']);
- $insertProduct->execute();
- }
- }
- foreach ($decodedResponse['product_exibition'] as $product_exibition) {
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
- $selectProduct->bindValue(':id_company', $product_exibition['id_company']);
- $selectProduct->bindValue(':id_product_off', $product_exibition['id_product']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- if ($product_exibition['sync'] == 'never') {
- $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)');
- $insertProductExibition->bindValue(':id_company', $product_exibition['id_company']);
- $insertProductExibition->bindValue(':id_product', $productId['id']);
- $insertProductExibition->bindValue(':id_product_exibition_off', $product_exibition['id']);
- $insertProductExibition->bindValue(':day', $product_exibition['day']);
- $insertProductExibition->bindValue(':at', $product_exibition['at']);
- $insertProductExibition->bindValue(':to', $product_exibition['to']);
- $insertProductExibition->bindValue(':display', $product_exibition['display']);
- $insertProductExibition->bindValue(':sync', 'yes');
- $insertProductExibition->bindValue(':deleted_at', $product_exibition['deleted_at']);
- $insertProductExibition->bindValue(':created_at', $product_exibition['created_at']);
- $insertProductExibition->bindValue(':updated_at', $product_exibition['updated_at']);
- $insertProductExibition->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $product_exibition['id'];
- // $objProductsExibition[] = $productArray;
- } else {
- $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');
- $insertProductExibition->bindValue(':id', $product_exibition['id']);
- $insertProductExibition->bindValue(':id_company', $product_exibition['id_company']);
- $insertProductExibition->bindValue(':id_product', $productId['id']);
- $insertProductExibition->bindValue(':day', $product_exibition['day']);
- $insertProductExibition->bindValue(':at', $product_exibition['at']);
- $insertProductExibition->bindValue(':to', $product_exibition['to']);
- $insertProductExibition->bindValue(':display', $product_exibition['display']);
- $insertProductExibition->bindValue(':sync', 'yes');
- $insertProductExibition->bindValue(':deleted_at', $product_exibition['deleted_at']);
- $insertProductExibition->bindValue(':created_at', $product_exibition['created_at']);
- $insertProductExibition->bindValue(':updated_at', $product_exibition['updated_at']);
- $insertProductExibition->execute();
- }
- }
- foreach ($decodedResponse['product_image'] as $product_exibition) {
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
- $selectProduct->bindValue(':id_company', $product_exibition['id_company']);
- $selectProduct->bindValue(':id_product_off', $product_exibition['id_product']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- if ($product_exibition['sync'] == 'never') {
- $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)');
- $insertProductImage->bindValue(':id_company', $product_exibition['id_company']);
- $insertProductImage->bindValue(':id_product_image_off', $product_exibition['id']);
- $insertProductImage->bindValue(':id_product', $productId['id']);
- $insertProductImage->bindValue(':order', $product_exibition['order']);
- $insertProductImage->bindValue(':image', $product_exibition['image']);
- $insertProductImage->bindValue(':status', $product_exibition['status']);
- $insertProductImage->bindValue(':sync', 'yes');
- $insertProductImage->bindValue(':deleted_at', $product_exibition['deleted_at']);
- $insertProductImage->bindValue(':created_at', $product_exibition['created_at']);
- $insertProductImage->bindValue(':updated_at', $product_exibition['updated_at']);
- $insertProductImage->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $product_exibition['id'];
- // $objProductImage[] = $productArray;
- } else {
- $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');
- $insertProductImage->bindValue(':id', $product_exibition['id']);
- $insertProductImage->bindValue(':id_company', $product_exibition['id_company']);
- $insertProductImage->bindValue(':id_product', $productId['id']);
- $insertProductImage->bindValue(':order', $product_exibition['order']);
- $insertProductImage->bindValue(':image', $product_exibition['image']);
- $insertProductImage->bindValue(':status', $product_exibition['status']);
- $insertProductImage->bindValue(':sync', 'yes');
- $insertProductImage->bindValue(':deleted_at', $product_exibition['deleted_at']);
- $insertProductImage->bindValue(':created_at', $product_exibition['created_at']);
- $insertProductImage->bindValue(':updated_at', $product_exibition['updated_at']);
- $insertProductImage->execute();
- }
- if (!empty($product_exibition['image'])) {
- $this->downloadImage($product_exibition['image']);
- }
- }
- foreach ($decodedResponse['product_preference'] as $product) {
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
- $selectProduct->bindValue(':id_company', $product['id_company']);
- $selectProduct->bindValue(':id_product_off', $product['id_product']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- $selectPreference = $conn->prepare('SELECT id from preference where id_company = :id_company and id_preference_off = :id_preference_off');
- $selectPreference->bindValue(':id_company', $product['id_company']);
- $selectPreference->bindValue(':id_preference_off', $product['id_preference']);
- $selectPreference->execute();
- $preferenceId = $selectPreference->fetch(PDO::FETCH_ASSOC);
- if ($product['sync'] == 'never') {
- $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)');
- $productPreference->bindValue(':id_company', $product['id_company']);
- $productPreference->bindValue(':id_product_preference_off', $product['id']);
- $productPreference->bindValue(':id_product', $productId['id']);
- $productPreference->bindValue(':id_preference', $preferenceId['id']);
- $productPreference->bindValue(':status', $product['status']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->bindValue(':deleted_at', $product['deleted_at']);
- $productPreference->bindValue(':created_at', $product['created_at']);
- $productPreference->bindValue(':updated_at', $product['updated_at']);
- $productPreference->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $product['id'];
- // $objProductPreference[] = $productArray;
- } else {
- $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');
- $productPreference->bindValue(':id', $product['id']);
- $productPreference->bindValue(':id_company', $product['id_company']);
- $productPreference->bindValue(':id_product', $productId['id']);
- $productPreference->bindValue(':id_preference', $preferenceId['id']);
- $productPreference->bindValue(':status', $product['status']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->bindValue(':deleted_at', $product['deleted_at']);
- $productPreference->bindValue(':created_at', $product['created_at']);
- $productPreference->bindValue(':updated_at', $product['updated_at']);
- $productPreference->execute();
- }
- }
- foreach ($decodedResponse['product_types'] as $product) {
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
- $selectProduct->bindValue(':id_company', $product['id_company']);
- $selectProduct->bindValue(':id_product_off', $product['id_product']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- if ($product['sync'] == 'never') {
- $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)');
- $productPreference->bindValue(':id_company', $product['id_company']);
- $productPreference->bindValue(':id_product_type_off', $product['id']);
- $productPreference->bindValue(':id_product', $productId['id']);
- $productPreference->bindValue(':name', $product['name']);
- $productPreference->bindValue(':price', $product['price']);
- $productPreference->bindValue(':description', $product['description']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->bindValue(':deleted_at', $product['deleted_at']);
- $productPreference->bindValue(':created_at', $product['created_at']);
- $productPreference->bindValue(':updated_at', $product['updated_at']);
- $productPreference->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $product['id'];
- // $objProductTypes[] = $productArray;
- } else {
- $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 ');
- $productPreference->bindValue(':id', $product['id']);
- $productPreference->bindValue(':id_company', $product['id_company']);
- $productPreference->bindValue(':id_product', $productId['id']);
- $productPreference->bindValue(':name', $product['name']);
- $productPreference->bindValue(':price', $product['price']);
- $productPreference->bindValue(':description', $product['description']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->bindValue(':deleted_at', $product['deleted_at']);
- $productPreference->bindValue(':created_at', $product['created_at']);
- $productPreference->bindValue(':updated_at', $product['updated_at']);
- $productPreference->execute();
- }
- }
- foreach ($decodedResponse['product_sales'] as $product) {
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
- $selectProduct->bindValue(':id_company', $product['id_company']);
- $selectProduct->bindValue(':id_product_off', $product['id_product']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- $selectSale = $conn->prepare('SELECT id from sale_type where id_company = :id_company and id_sale_type_off = :id_sale_type_off');
- $selectSale->bindValue(':id_company', $product['id_company']);
- $selectSale->bindValue(':id_sale_type_off', $product['id_sale_type']);
- $selectSale->execute();
- $saleId = $selectSale->fetch(PDO::FETCH_ASSOC);
- if ($product['sync'] == 'never') {
- $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)');
- $productPreference->bindValue(':id_company', $product['id_company']);
- $productPreference->bindValue(':id_product_sale_off', $product['id']);
- $productPreference->bindValue(':id_product', $productId['id']);
- $productPreference->bindValue(':id_sale_type', $saleId['id']);
- $productPreference->bindValue(':quantity', $product['quantity']);
- $productPreference->bindValue(':day', $product['day']);
- $productPreference->bindValue(':month', $product['month']);
- $productPreference->bindValue(':year', $product['year']);
- $productPreference->bindValue(':at', $product['at']);
- $productPreference->bindValue(':to', $product['to']);
- $productPreference->bindValue(':status', $product['status']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->bindValue(':deleted_at', $product['deleted_at']);
- $productPreference->bindValue(':created_at', $product['created_at']);
- $productPreference->bindValue(':updated_at', $product['updated_at']);
- $productPreference->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $product['id'];
- // $objProductSale[] = $productArray;
- } else {
- $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');
- $productPreference->bindValue(':id', $product['id']);
- $productPreference->bindValue(':id_company', $product['id_company']);
- $productPreference->bindValue(':id_product', $productId['id']);
- $productPreference->bindValue(':id_sale_type', $saleId['id']);
- $productPreference->bindValue(':quantity', $product['quantity']);
- $productPreference->bindValue(':day', $product['day']);
- $productPreference->bindValue(':month', $product['month']);
- $productPreference->bindValue(':year', $product['year']);
- $productPreference->bindValue(':at', $product['at']);
- $productPreference->bindValue(':to', $product['to']);
- $productPreference->bindValue(':status', $product['status']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->bindValue(':deleted_at', $product['deleted_at']);
- $productPreference->bindValue(':created_at', $product['created_at']);
- $productPreference->bindValue(':updated_at', $product['updated_at']);
- $productPreference->execute();
- }
- }
- foreach ($decodedResponse['product_tags'] as $product) {
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
- $selectProduct->bindValue(':id_company', $product['id_company']);
- $selectProduct->bindValue(':id_product_off', $product['id_product']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- if ($product['sync'] == 'never') {
- $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)');
- $productPreference->bindValue(':id_company', $product['id_company']);
- $productPreference->bindValue(':id_product_tag_off', $product['id']);
- $productPreference->bindValue(':id_product', $productId['id']);
- $productPreference->bindValue(':id_tag', $product['id_tag']);
- $productPreference->bindValue(':status', $product['status']);
- $productPreference->bindValue(':display', $product['display']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->bindValue(':deleted_at', $product['deleted_at']);
- $productPreference->bindValue(':created_at', $product['created_at']);
- $productPreference->bindValue(':updated_at', $product['updated_at']);
- $productPreference->execute();
- $productArray['id_off'] = $conn->lastInsertId();
- $productArray['online_id'] = $product['id'];
- $objProductTag[] = $productArray;
- } else {
- $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');
- $productPreference->bindValue(':id', $product['id']);
- $productPreference->bindValue(':id_company', $product['id_company']);
- $productPreference->bindValue(':id_product', $productId['id']);
- $productPreference->bindValue(':id_tag', $product['id_tag']);
- $productPreference->bindValue(':status', $product['status']);
- $productPreference->bindValue(':display', $product['display']);
- $productPreference->bindValue(':sync', 'yes');
- $productPreference->bindValue(':deleted_at', $product['deleted_at']);
- $productPreference->bindValue(':created_at', $product['created_at']);
- $productPreference->bindValue(':updated_at', $product['updated_at']);
- $productPreference->execute();
- }
- }
- foreach ($decodedResponse['table'] as $table) {
- $selectWaiter = $conn->prepare('SELECT id from company_user where id_company = :id_company and id_company_user_off = :id_waiter');
- $selectWaiter->bindValue(':id_company', $table['id_company']);
- $selectWaiter->bindValue(':id_waiter', $table['id_waiter']);
- $selectWaiter->execute();
- $waiterId = $selectWaiter->fetch(PDO::FETCH_ASSOC);
- if ($table['sync'] == 'never') {
- $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)');
- $insertTable->bindValue(':id_company', $table['id_company']);
- $insertTable->bindValue(':id_table_off', $table['id']);
- $insertTable->bindValue(':id_waiter', $waiterId['id']);
- $insertTable->bindValue(':num', $table['number']);
- $insertTable->bindValue(':sync', 'yes');
- $insertTable->bindValue(':deleted_at', $table['deleted_at']);
- $insertTable->bindValue(':created_at', $table['created_at']);
- $insertTable->bindValue(':updated_at', $table['updated_at']);
- $insertTable->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $table['id'];
- // $objTable[] = $productArray;
- } else {
- $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');
- $insertTable->bindValue(':id', $table['id']);
- $insertTable->bindValue(':id_company', $table['id_company']);
- $insertTable->bindValue(':id_waiter', $waiterId['id']);
- $insertTable->bindValue(':num', $table['number']);
- $insertTable->bindValue(':sync', 'yes');
- $insertTable->bindValue(':deleted_at', $table['deleted_at']);
- $insertTable->bindValue(':created_at', $table['created_at']);
- $insertTable->bindValue(':updated_at', $table['updated_at']);
- $insertTable->execute();
- }
- }
- foreach ($decodedResponse['command_table'] as $command_table) {
- $selectProduct = $conn->prepare('SELECT id from `table` where id_company = :id_company and id_table_off = :id_table_off');
- $selectProduct->bindValue(':id_company', $command_table['id_company']);
- $selectProduct->bindValue(':id_table_off', $command_table['id_table']);
- $selectProduct->execute();
- $tableId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- $selectProduct = $conn->prepare('SELECT id from command where id_company = :id_company and id_command_off = :id_command_off');
- $selectProduct->bindValue(':id_company', $command_table['id_company']);
- $selectProduct->bindValue(':id_command_off', $command_table['id_command']);
- $selectProduct->execute();
- $commandId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- if ($command_table['sync'] == 'never') {
- $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)');
- $insertCommandTable->bindValue(':id_command_table_off', $command_table['id']);
- $insertCommandTable->bindValue(':id_company', $command_table['id_company']);
- $insertCommandTable->bindValue(':id_table', $tableId['id']);
- $insertCommandTable->bindValue(':id_command', $commandId['id']);
- $insertCommandTable->bindValue(':sync', 'yes');
- $insertCommandTable->bindValue(':deleted_at', $command_table['deleted_at']);
- $insertCommandTable->bindValue(':created_at', $command_table['created_at']);
- $insertCommandTable->bindValue(':updated_at', $command_table['updated_at']);
- $insertCommandTable->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $command_table['id'];
- // $objCommandTable[] = $productArray;
- } else {
- $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');
- $insertCommandTable->bindValue(':id', $command_table['id']);
- $insertCommandTable->bindValue(':id_company', $command_table['id_company']);
- $insertCommandTable->bindValue(':id_table', $tableId['id']);
- $insertCommandTable->bindValue(':id_command', $commandId['id']);
- $insertCommandTable->bindValue(':sync', 'yes');
- $insertCommandTable->bindValue(':deleted_at', $command_table['deleted_at']);
- $insertCommandTable->bindValue(':created_at', $command_table['created_at']);
- $insertCommandTable->bindValue(':updated_at', $command_table['updated_at']);
- $insertCommandTable->execute();
- }
- }
- foreach ($decodedResponse['combo'] as $combo) {
- if ($combo['sync'] == 'never') {
- $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)');
- $insertCombo->bindValue(':id_company', $combo['id_company']);
- $insertCombo->bindValue(':id_combo_off', $combo['id']);
- $insertCombo->bindValue(':price', $combo['price']);
- $insertCombo->bindValue(':active', $combo['active']);
- $insertCombo->bindValue(':all_you_can_eat', $combo['all_you_can_eat']);
- $insertCombo->bindValue(':name', $combo['name']);
- $insertCombo->bindValue(':description', $combo['description']);
- $insertCombo->bindValue(':sync', 'yes');
- $insertCombo->bindValue(':deleted_at', $combo['deleted_at']);
- $insertCombo->bindValue(':created_at', $combo['created_at']);
- $insertCombo->bindValue(':updated_at', $combo['updated_at']);
- $insertCombo->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $combo['id'];
- // $comboOnlineId = $combo['id'];
- // $comboOfflineId = $productArray['id_off'];
- // $objCombo[] = $productArray;
- } else {
- $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');
- $insertCombo->bindValue(':id', $combo['id']);
- $insertCombo->bindValue(':id_company', $combo['id_company']);
- $insertCombo->bindValue(':price', $combo['price']);
- $insertCombo->bindValue(':active', $combo['active']);
- $insertCombo->bindValue(':all_you_can_eat', $combo['all_you_can_eat']);
- $insertCombo->bindValue(':name', $combo['name']);
- $insertCombo->bindValue(':description', $combo['description']);
- $insertCombo->bindValue(':sync', 'yes');
- $insertCombo->bindValue(':deleted_at', $combo['deleted_at']);
- $insertCombo->bindValue(':created_at', $combo['created_at']);
- $insertCombo->bindValue(':updated_at', $combo['updated_at']);
- $insertCombo->execute();
- }
- }
- foreach ($decodedResponse['combo_group'] as $combo_group) {
- $selectCombo = $conn->prepare('SELECT id from combo where id_company = :id_company and id_combo_off = :id_combo_off');
- $selectCombo->bindValue(':id_company', $combo_group['company_id']);
- $selectCombo->bindValue(':id_combo_off', $combo_group['combo_id']);
- $selectCombo->execute();
- $comboId = $selectCombo->fetch(PDO::FETCH_ASSOC);
- if ($combo_group['sync'] == 'never') {
- $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)');
- $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
- $insertComboGroup->bindValue(':id_combo_group_off', $combo_group['id']);
- $insertComboGroup->bindValue(':name', $combo_group['name']);
- $insertComboGroup->bindValue(':combo_id', $comboId['id']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
- $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
- $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
- $insertComboGroup->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $combo_group['id'];
- // $comboGroupOnlineId = $combo_group['id'];
- // $comboGroupOffId = $productArray['id_off'];
- // $objComboGroup[] = $productArray;
- } else {
- $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');
- $insertComboGroup->bindValue(':id', $combo_group['id']);
- $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
- $insertComboGroup->bindValue(':name', $combo_group['name']);
- $insertComboGroup->bindValue(':combo_id', $comboId['id']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
- $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
- $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
- $insertComboGroup->execute();
- }
- }
- foreach ($decodedResponse['combo_group_item'] as $combo_group) {
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
- $selectProduct->bindValue(':id_company', $combo_group['company_id']);
- $selectProduct->bindValue(':id_product_off', $combo_group['product_id']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- $selectCombo = $conn->prepare('SELECT id from combo_group where company_id = :id_company and id_combo_group_off = :id_combo_group_off');
- $selectCombo->bindValue(':id_company', $combo_group['company_id']);
- $selectCombo->bindValue(':id_combo_group_off', $combo_group['combo_group_id']);
- $selectCombo->execute();
- $comboGroupId = $selectCombo->fetch(PDO::FETCH_ASSOC);
- if ($combo_group['sync'] == 'never') {
- $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)');
- $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
- $insertComboGroup->bindValue(':id_combo_group_item_off', $combo_group['id']);
- $insertComboGroup->bindValue(':product_id', $productId['id']);
- $insertComboGroup->bindValue(':combo_group_id', $comboGroupId['id']);
- $insertComboGroup->bindValue(':order', $combo_group['order']);
- $insertComboGroup->bindValue(':additional_price', $combo_group['additional_price']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
- $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
- $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
- $insertComboGroup->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $combo_group['id'];
- // $objComboGroupItem[] = $productArray;
- } else {
- $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');
- $insertComboGroup->bindValue(':id', $combo_group['id']);
- $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
- $insertComboGroup->bindValue(':product_id', $productId['id']);
- $insertComboGroup->bindValue(':combo_group_id', $comboGroupId['id']);
- $insertComboGroup->bindValue(':order', $combo_group['order']);
- $insertComboGroup->bindValue(':additional_price', $combo_group['additional_price']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
- $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
- $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
- $insertComboGroup->execute();
- }
- }
- foreach ($decodedResponse['combo_exibition'] as $combo_group) {
- $selectCombo = $conn->prepare('SELECT id from combo where id_company = :id_company and id_combo_off = :id_combo_off');
- $selectCombo->bindValue(':id_company', $combo_group['company_id']);
- $selectCombo->bindValue(':id_combo_off', $combo_group['combo_id']);
- $selectCombo->execute();
- $comboId = $selectCombo->fetch(PDO::FETCH_ASSOC);
- if ($combo_group['sync'] == 'never') {
- $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)');
- $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
- $insertComboGroup->bindValue(':id_combo_exibition_off', $combo_group['id']);
- $insertComboGroup->bindValue(':at', $combo_group['at']);
- $insertComboGroup->bindValue(':to', $combo_group['to']);
- $insertComboGroup->bindValue(':combo_id', $comboId['id']);
- $insertComboGroup->bindValue(':display', $combo_group['display']);
- $insertComboGroup->bindValue(':day', $combo_group['day']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
- $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
- $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
- $insertComboGroup->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $combo_group['id'];
- // $objComboExibition[] = $productArray;
- } else {
- $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');
- $insertComboGroup->bindValue(':id', $combo_group['id']);
- $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
- $insertComboGroup->bindValue(':at', $combo_group['at']);
- $insertComboGroup->bindValue(':to', $combo_group['to']);
- $insertComboGroup->bindValue(':combo_id', $comboId['id']);
- $insertComboGroup->bindValue(':display', $combo_group['display']);
- $insertComboGroup->bindValue(':day', $combo_group['day']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
- $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
- $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
- $insertComboGroup->execute();
- }
- }
- foreach ($decodedResponse['combo_type'] as $combo_group) {
- $selectCombo = $conn->prepare('SELECT id from combo where id_company = :id_company and id_combo_off = :id_combo_off');
- $selectCombo->bindValue(':id_company', $combo_group['company_id']);
- $selectCombo->bindValue(':id_combo_off', $combo_group['combo_id']);
- $selectCombo->execute();
- $comboId = $selectCombo->fetch(PDO::FETCH_ASSOC);
- if ($combo_group['sync'] == 'never') {
- $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)');
- $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
- $insertComboGroup->bindValue(':id_combo_type_off', $combo_group['id']);
- $insertComboGroup->bindValue(':name', $combo_group['name']);
- $insertComboGroup->bindValue(':combo_id', $comboId['id']);
- $insertComboGroup->bindValue(':description', $combo_group['description']);
- $insertComboGroup->bindValue(':price', $combo_group['price']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
- $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
- $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
- $insertComboGroup->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $combo_group['id'];
- // $objComboType[] = $productArray;
- } else {
- $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');
- $insertComboGroup->bindValue(':id', $combo_group['id']);
- $insertComboGroup->bindValue(':company_id', $combo_group['company_id']);
- $insertComboGroup->bindValue(':name', $combo_group['name']);
- $insertComboGroup->bindValue(':combo_id', $comboId['id']);
- $insertComboGroup->bindValue(':description', $combo_group['description']);
- $insertComboGroup->bindValue(':price', $combo_group['price']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
- $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
- $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
- $insertComboGroup->execute();
- }
- }
- foreach ($decodedResponse['combo_image'] as $combo_group) {
- $selectCombo = $conn->prepare('SELECT id from combo where id_company = :id_company and id_combo_off = :id_combo_off');
- $selectCombo->bindValue(':id_company', $combo_group['id_company']);
- $selectCombo->bindValue(':id_combo_off', $combo_group['id_combo']);
- $selectCombo->execute();
- $comboId = $selectCombo->fetch(PDO::FETCH_ASSOC);
- if ($combo_group['sync'] == 'never') {
- $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)');
- $insertComboGroup->bindValue(':id_company', $combo_group['id_company']);
- $insertComboGroup->bindValue(':id_combo_image_off', $combo_group['id']);
- $insertComboGroup->bindValue(':image', $combo_group['image']);
- $insertComboGroup->bindValue(':id_combo', $comboId['id']);
- $insertComboGroup->bindValue(':order', $combo_group['order']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
- $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
- $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
- $insertComboGroup->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $combo_group['id'];
- // $objComboType[] = $productArray;
- } else {
- $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');
- $insertComboGroup->bindValue(':id', $combo_group['id']);
- $insertComboGroup->bindValue(':id_company', $combo_group['id_company']);
- $insertComboGroup->bindValue(':image', $combo_group['image']);
- $insertComboGroup->bindValue(':id_combo', $comboId['id']);
- $insertComboGroup->bindValue(':order', $combo_group['order']);
- $insertComboGroup->bindValue(':sync', 'yes');
- $insertComboGroup->bindValue(':deleted_at', $combo_group['deleted_at']);
- $insertComboGroup->bindValue(':created_at', $combo_group['created_at']);
- $insertComboGroup->bindValue(':updated_at', $combo_group['updated_at']);
- $insertComboGroup->execute();
- }
- if (!empty($combo_group['image'])) {
- $this->downloadImage($combo_group['image']);
- }
- }
- foreach ($decodedResponse['restaurant_campaign'] as $campaign) {
- if ($campaign['sync'] == 'never') {
- $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)');
- $insertCampaign->bindValue(':id_company', $campaign['id_company']);
- $insertCampaign->bindValue(':id_restaurant_campaign_off', $campaign['id']);
- $insertCampaign->bindValue(':click_counter', $campaign['click_counter']);
- $insertCampaign->bindValue(':name', $campaign['name']);
- $insertCampaign->bindValue(':active', $campaign['active']);
- $insertCampaign->bindValue(':campaign_type', $campaign['campaign_type']);
- $insertCampaign->bindValue(':image', $campaign['image']);
- $insertCampaign->bindValue(':order', $campaign['order']);
- $insertCampaign->bindValue(':url', $campaign['url']);
- $insertCampaign->bindValue(':sync', 'yes');
- $insertCampaign->bindValue(':deleted_at', $campaign['deleted_at']);
- $insertCampaign->bindValue(':created_at', $campaign['created_at']);
- $insertCampaign->bindValue(':updated_at', $campaign['updated_at']);
- $insertCampaign->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $campaign['id'];
- // $RestaurantOnline = $campaign['id'];
- // $RestaurantOffId = $productArray['id_off'];
- // $objRestaurantCampaign[] = $productArray;
- } else {
- $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');
- $insertCampaign->bindValue(':id', $campaign['id']);
- $insertCampaign->bindValue(':id_company', $campaign['id_company']);
- $insertCampaign->bindValue(':click_counter', $campaign['click_counter']);
- $insertCampaign->bindValue(':name', $campaign['name']);
- $insertCampaign->bindValue(':campaign_type', $campaign['campaign_type']);
- $insertCampaign->bindValue(':image', $campaign['image']);
- $insertCampaign->bindValue(':active', $campaign['active']);
- $insertCampaign->bindValue(':order', $campaign['order']);
- $insertCampaign->bindValue(':url', $campaign['url']);
- $insertCampaign->bindValue(':sync', 'yes');
- $insertCampaign->bindValue(':deleted_at', $campaign['deleted_at']);
- $insertCampaign->bindValue(':created_at', $campaign['created_at']);
- $insertCampaign->bindValue(':updated_at', $campaign['updated_at']);
- $insertCampaign->execute();
- }
- if (!empty($campaign['image'])) {
- $this->downloadImage($campaign['image']);
- }
- }
- foreach ($decodedResponse['restaurant_campaign_product'] as $campaign) {
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product_off');
- $selectProduct->bindValue(':id_company', $campaign['id_company']);
- $selectProduct->bindValue(':id_product_off', $campaign['id_product']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- $selectCampaign = $conn->prepare('SELECT id from restaurant_campaign where id_company = :id_company and id_restaurant_campaign_off = :id_restaurant_campaign_off');
- $selectCampaign->bindValue(':id_company', $campaign['id_company']);
- $selectCampaign->bindValue(':id_restaurant_campaign_off', $campaign['id_campaign']);
- $selectCampaign->execute();
- $campaignId = $selectCampaign->fetch(PDO::FETCH_ASSOC);
- if ($campaign['sync'] == 'never') {
- $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)');
- $insertCampaign->bindValue(':id_company', $campaign['id_company']);
- $insertCampaign->bindValue(':id_restaurant_campaign_product_off', $campaign['id']);
- $insertCampaign->bindValue(':id_product', $productId['id']);
- $insertCampaign->bindValue(':id_campaign', $campaignId['id']);
- $insertCampaign->bindValue(':sync', 'yes');
- $insertCampaign->bindValue(':deleted_at', $campaign['deleted_at']);
- $insertCampaign->bindValue(':created_at', $campaign['created_at']);
- $insertCampaign->bindValue(':updated_at', $campaign['updated_at']);
- $insertCampaign->execute();
- // $productArray['id_off'] = $conn->lastInsertId();
- // $productArray['online_id'] = $campaign['id'];
- // $objRestaurantCampaignProduct[] = $productArray;
- } else {
- $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');
- $insertCampaign->bindValue(':id', $campaign['id']);
- $insertCampaign->bindValue(':id_company', $campaign['id_company']);
- $insertCampaign->bindValue(':id_product', $productId['id']);
- $insertCampaign->bindValue(':id_campaign', $campaignId['id']);
- $insertCampaign->bindValue(':sync', 'yes');
- $insertCampaign->bindValue(':deleted_at', $campaign['deleted_at']);
- $insertCampaign->bindValue(':created_at', $campaign['created_at']);
- $insertCampaign->bindValue(':updated_at', $campaign['updated_at']);
- $insertCampaign->execute();
- }
- }
- foreach ($decodedResponse['order'] as $order) {
- //seleciona a mesa
- $selectTable = $conn->prepare('SELECT id from `table` where id_company = :id_company and id_table_off = :id_table');
- $selectTable->bindValue(':id_company', $order['id_company']);
- $selectTable->bindValue(':id_table', $order['id_table']);
- $selectTable->execute();
- $tableId = $selectTable->fetch(PDO::FETCH_ASSOC);
- //seleciona a comanda
- $selectCommand = $conn->prepare('SELECT id from command where id_company = :id_company and id_command_off = :id_command');
- $selectCommand->bindValue(':id_company', $order['id_company']);
- $selectCommand->bindValue(':id_command', $order['id_command']);
- $selectCommand->execute();
- $commandId = $selectCommand->fetch(PDO::FETCH_ASSOC);
- if ($order['sync'] == 'never') {
- $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)');
- $orderInsert->bindValue(':id_table', $tableId['id']);
- $orderInsert->bindValue(':id_company', $order['id_company']);
- $orderInsert->bindValue(':id_command', $commandId['id']);
- $orderInsert->bindValue(':id', $order['id']);
- $orderInsert->bindValue(':status', $order['status']);
- $orderInsert->bindValue(':use_service', $order['use_service']);
- $orderInsert->bindValue(':sync', 'yes');
- $orderInsert->bindValue(':created_at', $order['created_at']);
- $orderInsert->bindValue(':updated_at', $order['updated_at']);
- $orderInsert->bindValue(':deleted_at', $order['deleted_at']);
- $orderInsert->execute();
- } else {
- $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');
- $orderInsert->bindValue(':id_table', $tableId['id']);
- $orderInsert->bindValue(':id_company', $order['id_company']);
- $orderInsert->bindValue(':id_command', $commandId['id']);
- $orderInsert->bindValue(':id', $order['id']);
- $orderInsert->bindValue(':status', $order['status']);
- $orderInsert->bindValue(':use_service', $order['use_service']);
- $orderInsert->bindValue(':sync', 'yes');
- $orderInsert->bindValue(':created_at', $order['created_at']);
- $orderInsert->bindValue(':updated_at', $order['updated_at']);
- $orderInsert->bindValue(':deleted_at', $order['deleted_at']);
- $orderInsert->execute();
- }
- }
- foreach ($decodedResponse['order_command'] as $command) {
- //seleciona a mesa
- $selectTable = $conn->prepare('SELECT id from `table` where id_company = :id_company and id_table_off = :id_table');
- $selectTable->bindValue(':id_company', $order['id_company']);
- $selectTable->bindValue(':id_table', $order['id_table']);
- $selectTable->execute();
- $tableId = $selectTable->fetch(PDO::FETCH_ASSOC);
- //seleciona a comanda
- $selectCommand = $conn->prepare('SELECT id from command where id_company = :id_company and id_command_off = :id_command');
- $selectCommand->bindValue(':id_company', $order['id_company']);
- $selectCommand->bindValue(':id_command', $order['id_command']);
- $selectCommand->execute();
- $commandId = $selectCommand->fetch(PDO::FETCH_ASSOC);
- //seleciona o pedido
- $selectOrder = $conn->prepare('SELECT id from `order` where id_company = :id_company and id_order_off = :id_order');
- $selectOrder->bindValue(':id_company', $command['id_company']);
- $selectOrder->bindValue(':id_order', $command['id_order']);
- $selectOrder->execute();
- $orderId = $selectOrder->fetch(PDO::FETCH_ASSOC);
- if ($command['sync'] == 'never') {
- $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)');
- $orderCommand->bindValue(':id_table', $tableId['id']);
- $orderCommand->bindValue(':id_company', $command['id_company']);
- $orderCommand->bindValue(':id_command', $commandId['id']);
- $orderCommand->bindValue(':id_order', $orderId['id']);
- $orderCommand->bindValue(':id', $command['id']);
- $orderCommand->bindValue(':sync', 'yes');
- $orderCommand->bindValue(':created_at', $command['created_at']);
- $orderCommand->bindValue(':updated_at', $command['updated_at']);
- $orderCommand->bindValue(':deleted_at', $command['deleted_at']);
- $orderCommand->execute();
- } else {
- $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');
- $orderCommand->bindValue(':id_table', $tableId['id']);
- $orderCommand->bindValue(':id_company', $command['id_company']);
- $orderCommand->bindValue(':id_command', $commandId['id']);
- $orderCommand->bindValue(':id_order', $orderId['id']);
- $orderCommand->bindValue(':id', $command['id']);
- $orderCommand->bindValue(':sync', 'yes');
- $orderCommand->bindValue(':created_at', $command['created_at']);
- $orderCommand->bindValue(':updated_at', $command['updated_at']);
- $orderCommand->bindValue(':deleted_at', $command['deleted_at']);
- $orderCommand->execute();
- }
- }
- foreach ($decodedResponse['order_items'] as $item) {
- //seleciona o pedido
- $selectOrder = $conn->prepare('SELECT id from `order` where id_company = :id_company and id_order_off = :id_order');
- $selectOrder->bindValue(':id_company', $item['id_company']);
- $selectOrder->bindValue(':id_order', $item['id_order']);
- $selectOrder->execute();
- $orderId = $selectOrder->fetch(PDO::FETCH_ASSOC);
- //seleciona o menu
- $selectMenu = $conn->prepare('SELECT id from menu_type where id_company = :id_company and id_menu_type_off = :id');
- $selectMenu->bindValue(':id_company', $item['id_company']);
- $selectMenu->bindValue(':id', $item['id']);
- $selectMenu->execute();
- $menuId = $selectMenu->fetch(PDO::FETCH_ASSOC);
- if ($item['is_combo'] == 'yes') {
- //seleciona o combo
- $selectCombo = $conn->prepare('SELECT id from combo where id_company = :id_company and id_combo_off = :id_combo');
- $selectCombo->bindValue(':id_company', $item['id_company']);
- $selectCombo->bindValue(':id_combo', $item['id_combo']);
- $selectCombo->execute();
- $comboId = $selectCombo->fetch(PDO::FETCH_ASSOC);
- //seleciona o tipo do combo
- $selectComboType = $conn->prepare('SELECT id from combo_type where company_id = :id_company and id_combo_type_off = :id_combo_type');
- $selectComboType->bindValue(':id_company', $item['id_company']);
- $selectComboType->bindValue(':id_combo_type', $item['id_combo_type']);
- $selectComboType->execute();
- $comboTypeId = $selectComboType->fetch(PDO::FETCH_ASSOC);
- } else {
- //seleciona o produto
- $selectProduct = $conn->prepare('SELECT id from product where id_company = :id_company and id_product_off = :id_product');
- $selectProduct->bindValue(':id_company', $item['id_company']);
- $selectProduct->bindValue(':id_product', $item['id_product']);
- $selectProduct->execute();
- $productId = $selectProduct->fetch(PDO::FETCH_ASSOC);
- //seleciona o tipo do produto
- $selectProductType = $conn->prepare('SELECT id from product_type where id_company = :id_company and id_product_type_off = :id_product_type');
- $selectProductType->bindValue(':id_company', $item['id_company']);
- $selectProductType->bindValue(':id_product_type', $item['id_product_type']);
- $selectProductType->execute();
- $productTypeId = $selectProductType->fetch(PDO::FETCH_ASSOC);
- }
- if ($item['sync'] == 'never') {
- $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)');
- $orderItemInsert->bindValue(':id_order', $orderId['id']);
- $orderItemInsert->bindValue(':id', $item['id']);
- $orderItemInsert->bindValue(':id_company', $item['id_company']);
- if ($item['is_combo'] == 'yes') {
- $orderItemInsert->bindValue(':id_combo', $comboId['id']);
- $orderItemInsert->bindValue(':id_combo_type', $comboTypeId['id']);
- $orderItemInsert->bindValue(':id_product_type', null);
- $orderItemInsert->bindValue(':id_product', null);
- } else {
- $orderItemInsert->bindValue(':id_product', $productId['id']);
- $orderItemInsert->bindValue(':id_combo', null);
- $orderItemInsert->bindValue(':id_combo_type', null);
- $orderItemInsert->bindValue(':id_product_type', $productTypeId['id']);
- }
- $orderItemInsert->bindValue(':id_menu_type', $menuId['id']);
- $orderItemInsert->bindValue(':obs', $item['obs']);
- $orderItemInsert->bindValue(':price', $item['price']);
- $orderItemInsert->bindValue(':quantity', $item['quantity']);
- $orderItemInsert->bindValue(':is_combo', $item['is_combo']);
- $orderItemInsert->bindValue(':sync', 'yes');
- $orderItemInsert->bindValue(':created_at', $item['created_at']);
- $orderItemInsert->bindValue(':updated_at', $item['updated_at']);
- $orderItemInsert->bindValue(':deleted_at', $item['deleted_at']);
- $orderItemInsert->execute();
- $orderItemId = $conn->lastInsertId();
- } else {
- $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
- id_order_item_off = :id');
- $orderItemInsert->bindValue(':id_order', $orderId['id']);
- $orderItemInsert->bindValue(':id', $item['id']);
- $orderItemInsert->bindValue(':id_company', $item['id_company']);
- if ($item['is_combo'] == 'yes') {
- $orderItemInsert->bindValue(':id_combo', $comboId['id']);
- $orderItemInsert->bindValue(':id_combo_type', $comboTypeId['id']);
- $orderItemInsert->bindValue(':id_product_type', null);
- $orderItemInsert->bindValue(':id_product', null);
- } else {
- $orderItemInsert->bindValue(':id_product', $productId['id']);
- $orderItemInsert->bindValue(':id_combo', null);
- $orderItemInsert->bindValue(':id_combo_type', null);
- $orderItemInsert->bindValue(':id_product_type', $productTypeId['id']);
- }
- $orderItemInsert->bindValue(':id_menu_type', $menuId['id']);
- $orderItemInsert->bindValue(':obs', $item['obs']);
- $orderItemInsert->bindValue(':price', $item['price']);
- $orderItemInsert->bindValue(':quantity', $item['quantity']);
- $orderItemInsert->bindValue(':is_combo', $item['is_combo']);
- $orderItemInsert->bindValue(':sync', 'yes');
- $orderItemInsert->bindValue(':created_at', $item['created_at']);
- $orderItemInsert->bindValue(':updated_at', $item['updated_at']);
- $orderItemInsert->bindValue(':deleted_at', $item['deleted_at']);
- $orderItemInsert->execute();
- }
- }
- foreach ($decodedResponse['additional_items'] as $itemAdditional) {
- //seleciona o item do pedido
- $selectOrderItem = $conn->prepare('SELECT id from order_item where id_company = :id_company and id_order_item_off = :id_order_item');
- $selectOrderItem->bindValue(':id_company', $itemAdditional['id_company']);
- $selectOrderItem->bindValue(':id_order_item', $itemAdditional['id_order_item']);
- $selectOrderItem->execute();
- $orderItemId = $selectOrderItem->fetch(PDO::FETCH_ASSOC);
- //seleciona o adicional
- $selectAdditional = $conn->prepare('SELECT id from additional where id_company = :id_company and id_additional_off = :id_additional');
- $selectAdditional->bindValue(':id_company', $itemAdditional['id_company']);
- $selectAdditional->bindValue(':id_additional', $itemAdditional['id_additional']);
- $selectAdditional->execute();
- $additionalId = $selectAdditional->fetch(PDO::FETCH_ASSOC);
- if ($item['sync'] == 'never') {
- $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)');
- $orderAdditional->bindValue(':id_order_item', $orderItemId['id']);
- $orderAdditional->bindValue(':id', $itemAdditional['id']);
- $orderAdditional->bindValue(':id_additional', $additionalId['id']);
- $orderAdditional->bindValue(':id_company', $itemAdditional['id_company']);
- $orderAdditional->bindValue(':sync', 'yes');
- $orderAdditional->bindValue(':created_at', $itemAdditional['created_at']);
- $orderAdditional->bindValue(':updated_at', $itemAdditional['updated_at']);
- $orderAdditional->bindValue(':deleted_at', $itemAdditional['deleted_at']);
- $orderAdditional->execute();
- } else {
- $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');
- $orderAdditional->bindValue(':id_order_item', $orderItemId['id']);
- $orderAdditional->bindValue(':id', $itemAdditional['id']);
- $orderAdditional->bindValue(':id_additional', $additionalId['id']);
- $orderAdditional->bindValue(':id_company', $itemAdditional['id_company']);
- $orderAdditional->bindValue(':sync', 'yes');
- $orderAdditional->bindValue(':created_at', $itemAdditional['created_at']);
- $orderAdditional->bindValue(':updated_at', $itemAdditional['updated_at']);
- $orderAdditional->bindValue(':deleted_at', $itemAdditional['deleted_at']);
- $orderAdditional->execute();
- }
- }
- foreach ($decodedResponse['preferences_items'] as $itemPreference) {
- //seleciona o item do pedido
- $selectOrderItem = $conn->prepare('SELECT id from order_item where id_company = :id_company and id_order_item_off = :id_order_item');
- $selectOrderItem->bindValue(':id_company', $itemPreference['id_company']);
- $selectOrderItem->bindValue(':id_order_item', $itemPreference['id_order_item']);
- $selectOrderItem->execute();
- $orderItemId = $selectOrderItem->fetch(PDO::FETCH_ASSOC);
- //seleciona a preferencia
- $selectPreference = $conn->prepare('SELECT id from preference where id_company = :id_company and id_preference_off = :id_preference');
- $selectPreference->bindValue(':id_company', $itemPreference['id_company']);
- $selectPreference->bindValue(':id_preference', $itemPreference['id_preference']);
- $selectPreference->execute();
- $preferenceId = $selectPreference->fetch(PDO::FETCH_ASSOC);
- //seleciona o item da preferencia
- $selectPreference = $conn->prepare('SELECT id from preference_item where id_company = :id_company and id_preference_item_off = :id_preference_item');
- $selectPreference->bindValue(':id_company', $itemPreference['id_company']);
- $selectPreference->bindValue(':id_preference_item', $itemPreference['id_preference_item']);
- $selectPreference->execute();
- $preferenceItemId = $selectPreference->fetch(PDO::FETCH_ASSOC);
- if ($itemPreference['sync'] == 'never') {
- $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)');
- $orderPreference->bindValue(':id_order_item', $orderItemId['id']);
- $orderPreference->bindValue(':id_company', $itemPreference['id_company']);
- $orderPreference->bindValue(':id', $itemPreference['id']);
- $orderPreference->bindValue(':id_preference', $preferenceId['id']);
- $orderPreference->bindValue(':id_preference_item', $preferenceItemId['id']);
- $orderPreference->bindValue(':sync', 'yes');
- $orderPreference->bindValue(':created_at', $itemPreference['created_at']);
- $orderPreference->bindValue(':updated_at', $itemPreference['updated_at']);
- $orderPreference->bindValue(':deleted_at', $itemPreference['deleted_at']);
- $orderPreference->execute();
- } else {
- $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');
- $orderPreference->bindValue(':id_order_item', $orderItemId['id']);
- $orderPreference->bindValue(':id_company', $itemPreference['id_company']);
- $orderPreference->bindValue(':id', $itemPreference['id']);
- $orderPreference->bindValue(':id_preference_item', $preferenceItemId['id']);
- $orderPreference->bindValue(':id_preference', $preferenceId['id']);
- $orderPreference->bindValue(':sync', 'yes');
- $orderPreference->bindValue(':created_at', $itemPreference['created_at']);
- $orderPreference->bindValue(':updated_at', $itemPreference['updated_at']);
- $orderPreference->bindValue(':deleted_at', $itemPreference['deleted_at']);
- $orderPreference->execute();
- }
- }
- $conn->commit();
- $list['error'] = 'false';
- return $list;
- }
- catch (Exception $e) {
- $conn->rollBack();
- $list['error'] = 'true';
- return $list;
- }
- }
- /**
- * Método utilizado para alterar todos os não sincronizados para sincronizados
- * @param Request $request [description]
- * @return [type] [description]
- */
- public function update(Request $request)
- {
- $conn = DatabaseUtils::getDB();
- $data = $request->all();
- $companyId = $data['id_company'];
- $userId = $data['userId'];
- $conn->beginTransaction();
- try {
- $stmt = $conn->prepare("SELECT DISTINCT COLUMN_NAME AS 'ColumnName'
- ,TABLE_NAME AS 'TableName'
- FROM INFORMATION_SCHEMA.COLUMNS
- WHERE COLUMN_NAME LIKE '%sync%'
- ORDER BY TableName
- ,ColumnName;");
- $stmt->execute();
- $update = $stmt->fetchAll(PDO::FETCH_ASSOC);
- foreach ($update as $as => $val) {
- $table_name = $val['TableName'];
- $query = 'UPDATE `' . $table_name . '` SET sync = :sync ';
- $up = $conn->prepare($query);
- $up->bindValue(':sync', 'yes');
- $up->execute();
- }
- $sincStmt = $conn->prepare('INSERT INTO sincronize (id_company) VALUES (:id_company)');
- $sincStmt->bindValue(':id_company', $companyId);
- $sincStmt->execute();
- $response['error'] = false;
- $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)');
- $logSync->bindValue(':id_user', $userId);
- $logSync->bindValue(':id_company', $companyId);
- $logSync->bindValue(':page', 'sincronizar');
- $logSync->bindValue(':message', 'Sincronização realizada com sucesso');
- $logSync->bindValue(':subject', 'Sincronização realizada');
- $logSync->bindValue(':sync', 'yes');
- $logSync->bindValue(':created_at', Carbon::now());
- $logSync->execute();
- $conn->commit();
- return json_encode($response);
- }
- catch (Exception $e) {
- $conn->rollBack();
- $response['error'] = true;
- return json_encode($response);
- }
- }
- /**
- * Método utilizado para selecionar todos não sincronizados
- * @param [type] $companyId [description]
- * @return [type] [description]
- */
- public function selectNoSync($companyId)
- {
- $conn = DatabaseUtils::getDB();
- $conn->beginTransaction();
- try {
- $additionalStmt = $conn->prepare('SELECT * FROM additional where sync = :sync and id_company = :id_company');
- $additionalStmt->bindValue(':sync', 'no');
- $additionalStmt->bindValue(':id_company', $companyId);
- $additionalStmt->execute();
- $additionals = $additionalStmt->fetchAll(PDO::FETCH_ASSOC);
- //passa os adicionais como indicé da variavel de retorno lista
- $list['additionals'] = $additionals;
- //BUSCA PELAS CATEGORIAS
- $categoryStmt = $conn->prepare('SELECT * from `category` where sync = :sync and id_company = :id_company');
- $categoryStmt->bindValue(':sync', 'no');
- $categoryStmt->bindValue(':id_company', $companyId);
- $categoryStmt->execute();
- $category = $categoryStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['category'] = $category;
- //BUSCA PELAS EXIBIÇÕES DE CATEGORIAS
- $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');
- $categoryExibitionStmt->bindValue(':sync', 'no');
- $categoryExibitionStmt->bindValue(':id_company', $companyId);
- $categoryExibitionStmt->execute();
- $categoryExibition = $categoryExibitionStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['category_exibition'] = $categoryExibition;
- //BUSCA PELAS COMANDAS
- $commandStmt = $conn->prepare('SELECT * from `command` where sync = :sync and id_company = :id_company');
- $commandStmt->bindValue(':sync', 'no');
- $commandStmt->bindValue(':id_company', $companyId);
- $commandStmt->execute();
- $command = $commandStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['command'] = $command;
- //BUSCA PELAS MESAS DE COMANDAS
- $commandTableStmt = $conn->prepare('SELECT * from `command_table` where sync = :sync and id_company = :id_company');
- $commandTableStmt->bindValue(':sync', 'no');
- $commandTableStmt->bindValue(':id_company', $companyId);
- $commandTableStmt->execute();
- $commandTable = $commandTableStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['command_table'] = $commandTable;
- //BUSCA PELAS EMPRESAS
- $companyStmt = $conn->prepare('SELECT * from `company` where sync = :sync and id = :id_company');
- $companyStmt->bindValue(':sync', 'no');
- $companyStmt->bindValue(':id_company', $companyId);
- $companyStmt->execute();
- $company = $companyStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['company'] = $company;
- //BUSCA PELOS USUÁRIOS DAS EMPRESAS
- $companyUserStmt = $conn->prepare('SELECT * from `company_user` where sync = :sync and id_company = :id_company');
- $companyUserStmt->bindValue(':sync', 'no');
- $companyUserStmt->bindValue(':id_company', $companyId);
- $companyUserStmt->execute();
- $companyUser = $companyUserStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['company_user'] = $companyUser;
- //BUSCA PELAS CONFIGURAÇÕES DAS EMPRESAS
- $configStmt = $conn->prepare('SELECT * from `config` where sync = :sync and id_company = :id_company');
- $configStmt->bindValue(':sync', 'no');
- $configStmt->bindValue(':id_company', $companyId);
- $configStmt->execute();
- $config = $configStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['config'] = $config;
- //BUSCA PELOS TIPOS DE MENU
- $menuStmt = $conn->prepare('SELECT * from `menu_type` where sync = :sync and id_company = :id_company');
- $menuStmt->bindValue(':sync', 'no');
- $menuStmt->bindValue(':id_company', $companyId);
- $menuStmt->execute();
- $menu = $menuStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['menu'] = $menu;
- //BUSCA PELAS PREFERÊNCIAS
- $preferenceStmt = $conn->prepare('SELECT * from `preference` where sync = :sync and id_company = :id_company');
- $preferenceStmt->bindValue(':sync', 'no');
- $preferenceStmt->bindValue(':id_company', $companyId);
- $preferenceStmt->execute();
- $preference = $preferenceStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['preference'] = $preference;
- //BUSCA PELAS CATEGORIAS DAS PREFERÊNCIAS
- $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');
- $preferenceCategoryStmt->bindValue(':sync', 'no');
- $preferenceCategoryStmt->bindValue(':id_company', $companyId);
- $preferenceCategoryStmt->execute();
- $preference_category = $preferenceCategoryStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['preference_category'] = $preference_category;
- //BUSCA PELOS ITENS DAS PREFERÊNCIAS
- $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');
- $preferenceItems->bindValue(':sync', 'no');
- $preferenceItems->bindValue(':id_company', $companyId);
- $preferenceItems->execute();
- $preference_item = $preferenceItems->fetchAll(PDO::FETCH_ASSOC);
- $list['preference_item'] = $preference_item;
- //BUSCA PELOS PRODUTOS
- $productsStmt = $conn->prepare('SELECT * from `product` where sync = :sync and id_company = :id_company');
- $productsStmt->bindValue(':sync', 'no');
- $productsStmt->bindValue(':id_company', $companyId);
- $productsStmt->execute();
- $products = $productsStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['products'] = $products;
- //BUSCA PELOS ADICIONAIS DOS PRODUTOS
- $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');
- $produtsAdditionalStmt->bindValue(':sync', 'no');
- $produtsAdditionalStmt->bindValue(':id_company', $companyId);
- $produtsAdditionalStmt->execute();
- $product_additionals = $produtsAdditionalStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['product_additionals'] = $product_additionals;
- //BUSCA PELOS PLANOS DAS EMPRESAS
- $companyPlanStmt = $conn->prepare('SELECT * from `company_plan_type`');
- $companyPlanStmt->execute();
- $plantType = $companyPlanStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['company_plan_type'] = $plantType;
- //BUSCA PELAS CATEGORIAS DOS PRODUTOS
- $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');
- $productsCategoryStmt->bindValue(':sync', 'no');
- $productsCategoryStmt->bindValue(':id_company', $companyId);
- $productsCategoryStmt->execute();
- $product_category = $productsCategoryStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['product_category'] = $product_category;
- //BUSCA PELAS IMAGENS DOS PRODUTOS
- $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');
- $productImages->bindValue(':sync', 'no');
- $productImages->bindValue(':id_company', $companyId);
- $productImages->execute();
- $product_image = $productImages->fetchAll(PDO::FETCH_ASSOC);
- $list['product_image'] = $product_image;
- //BUSCA PELAS EXIBIÇÕES DOS PRODUTOS
- $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');
- $productsExibitionStmt->bindValue(':id_company', $companyId);
- $productsExibitionStmt->bindValue(':sync', 'no');
- $productsExibitionStmt->execute();
- $product_exibition = $productsExibitionStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['product_exibition'] = $product_exibition;
- //BUSCA PELAS PREFERÊNCIAS DOS PRODUTOS
- $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');
- $productPreference->bindValue(':sync', 'no');
- $productPreference->bindValue(':id_company', $companyId);
- $productPreference->execute();
- $product_preference = $productPreference->fetchAll(PDO::FETCH_ASSOC);
- $list['product_preference'] = $product_preference;
- //BUSCA PELAS VENDAS DOS PRODUTOS
- $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');
- $productSales->bindValue(':sync', 'no');
- $productSales->bindValue(':id_company', $companyId);
- $productSales->execute();
- $product_sales = $productSales->fetchAll(PDO::FETCH_ASSOC);
- $list['product_sales'] = $product_sales;
- //BUSCA PELAS TAGS DOS PRODUTOS
- $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');
- $productTags->bindValue(':sync', 'no');
- $productTags->bindValue(':id_company', $companyId);
- $productTags->execute();
- $product_tags = $productTags->fetchAll(PDO::FETCH_ASSOC);
- $list['product_tags'] = $product_tags;
- //BUSCA PELOS TIPOS DOS PRODUTOS
- $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');
- $productType->bindValue(':sync', 'no');
- $productType->bindValue(':id_company', $companyId);
- $productType->execute();
- $product_types = $productType->fetchAll(PDO::FETCH_ASSOC);
- $list['product_types'] = $product_types;
- //BUSCA PELOS TIPOS De VENDAS
- $saleType = $conn->prepare('SELECT * from `sale_type` where sync = :sync and id_company = :id_company');
- $saleType->bindValue(':sync', 'no');
- $saleType->bindValue(':id_company', $companyId);
- $saleType->execute();
- $sale_type = $saleType->fetchAll(PDO::FETCH_ASSOC);
- $list['sale_type'] = $sale_type;
- //BUSCA PELAS MESAS
- $tableStmt = $conn->prepare('SELECT * from `table` where sync = :sync and id_company = :id_company');
- $tableStmt->bindValue(':sync', 'no');
- $tableStmt->bindValue(':id_company', $companyId);
- $tableStmt->execute();
- $table = $tableStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['table'] = $table;
- //BUSCA PELAS MESAS
- $tagStmt = $conn->prepare('SELECT * from `tag` where sync = :sync ');
- $tagStmt->bindValue(':sync', 'no');
- $tagStmt->execute();
- $tag = $tagStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['tag'] = $tag;
- //BUSCA PELAS TIPOS DE AUDIÊNCIAS
- $target = $conn->prepare('SELECT * from `target_audience` where sync = :sync and id_company = :id_company');
- $target->bindValue(':sync', 'no');
- $target->bindValue(':id_company', $companyId);
- $target->execute();
- $targetAudience = $target->fetchAll(PDO::FETCH_ASSOC);
- $list['target'] = $targetAudience;
- //BUSCA PELOS COMBOS
- $comboStmt = $conn->prepare('SELECT * from `combo` where sync = :sync and id_company = :id_company');
- $comboStmt->bindValue(':sync', 'no');
- $comboStmt->bindValue(':id_company', $companyId);
- $comboStmt->execute();
- $combo = $comboStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['combo'] = $combo;
- //BUSCA PELOS COMBOS
- $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');
- $comboGroup->bindValue(':sync', 'no');
- $comboGroup->bindValue(':id_company', $companyId);
- $comboGroup->execute();
- $combo = $comboGroup->fetchAll(PDO::FETCH_ASSOC);
- $list['combo_group'] = $combo;
- //BUSCA PELOS COMBOS
- $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');
- $comboGroupItem->bindValue(':sync', 'no');
- $comboGroupItem->bindValue(':id_company', $companyId);
- $comboGroupItem->execute();
- $combo = $comboGroupItem->fetchAll(PDO::FETCH_ASSOC);
- $list['combo_group_item'] = $combo;
- //BUSCA PELOS COMBOS
- $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');
- $comboType->bindValue(':sync', 'no');
- $comboType->bindValue(':id_company', $companyId);
- $comboType->execute();
- $combo = $comboType->fetchAll(PDO::FETCH_ASSOC);
- $list['combo_type'] = $combo;
- //BUSCA PELOS COMBOS
- $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');
- $comboType->bindValue(':sync', 'no');
- $comboType->bindValue(':id_company', $companyId);
- $comboType->execute();
- $combo = $comboType->fetchAll(PDO::FETCH_ASSOC);
- $list['combo_image'] = $combo;
- //BUSCA PELOS COMBOS
- $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');
- $comboExibition->bindValue(':sync', 'no');
- $comboExibition->bindValue(':id_company', $companyId);
- $comboExibition->execute();
- $combo = $comboExibition->fetchAll(PDO::FETCH_ASSOC);
- $list['combo_exibition'] = $combo;
- //BUSCA PELAS CAMPANHAS
- $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) ');
- $campaignStmt->bindValue(':sync', 'no');
- $campaignStmt->bindValue(':company_id', $companyId);
- $campaignStmt->execute();
- $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['campaign'] = $campaign;
- //BUSCA PELAS EMPRESAS PARA INSERIR AS CAMPANHAS
- $campaignStmt = $conn->prepare('SELECT * from campaign_company where id_company = :company_id and sync = :sync');
- $campaignStmt->bindValue(':sync', 'no');
- $campaignStmt->bindValue(':company_id', $companyId);
- $campaignStmt->execute();
- $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['campaign_company'] = $campaign;
- //BUSCA PELAS campanhas de empresas
- $campaignStmt = $conn->prepare('SELECT * from restaurant_campaign where id_company = :company_id and sync = :sync');
- $campaignStmt->bindValue(':sync', 'no');
- $campaignStmt->bindValue(':company_id', $companyId);
- $campaignStmt->execute();
- $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['restaurant_campaign'] = $campaign;
- //BUSCA PELAS PRODUTOS CADASTRADOS EM CAMPANHAS DE EMPRESAS
- $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');
- $campaignStmt->bindValue(':sync', 'no');
- $campaignStmt->bindValue(':company_id', $companyId);
- $campaignStmt->execute();
- $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['restaurant_campaign_product'] = $campaign;
- $conn->commit();
- return $list;
- }
- catch (Exception $e) {
- $conn->rollBack();
- return ApiResponse::returnResponse(true, $e->getMessage(), null);
- }
- }
- /**
- * Método que seleciona dados nunca sincronizados
- * @param [type] $companyId [description]
- * @return [type] [description]
- */
- public function selectNeverSync($companyId)
- {
- $conn = DatabaseUtils::getDB();
- $conn->beginTransaction();
- try {
- $additionalStmt = $conn->prepare('SELECT * FROM additional where sync = :sync and id_company = :id_company');
- $additionalStmt->bindValue(':sync', 'never');
- $additionalStmt->bindValue(':id_company', $companyId);
- $additionalStmt->execute();
- $additionals = $additionalStmt->fetchAll(PDO::FETCH_ASSOC);
- //passa os adicionais como indicé da variavel de retorno lista
- $list['additionals'] = $additionals;
- //BUSCA PELAS CATEGORIAS
- $categoryStmt = $conn->prepare('SELECT * from `category` where sync = :sync and id_company = :id_company');
- $categoryStmt->bindValue(':sync', 'never');
- $categoryStmt->bindValue(':id_company', $companyId);
- $categoryStmt->execute();
- $category = $categoryStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['category'] = $category;
- //BUSCA PELAS EXIBIÇÕES DE CATEGORIAS
- $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');
- $categoryExibitionStmt->bindValue(':sync', 'never');
- $categoryExibitionStmt->bindValue(':id_company', $companyId);
- $categoryExibitionStmt->execute();
- $categoryExibition = $categoryExibitionStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['category_exibition'] = $categoryExibition;
- //BUSCA PELAS COMANDAS
- $commandStmt = $conn->prepare('SELECT * from `command` where sync = :sync and id_company = :id_company');
- $commandStmt->bindValue(':sync', 'never');
- $commandStmt->bindValue(':id_company', $companyId);
- $commandStmt->execute();
- $command = $commandStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['command'] = $command;
- //BUSCA PELAS MESAS DE COMANDAS
- $commandTableStmt = $conn->prepare('SELECT * from `command_table` where sync = :sync and id_company = :id_company');
- $commandTableStmt->bindValue(':sync', 'never');
- $commandTableStmt->bindValue(':id_company', $companyId);
- $commandTableStmt->execute();
- $commandTable = $commandTableStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['command_table'] = $commandTable;
- //BUSCA PELAS EMPRESAS
- $companyStmt = $conn->prepare('SELECT * from `company` where sync = :sync and id = :id_company');
- $companyStmt->bindValue(':sync', 'never');
- $companyStmt->bindValue(':id_company', $companyId);
- $companyStmt->execute();
- $company = $companyStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['company'] = $company;
- //BUSCA PELOS USUÁRIOS DAS EMPRESAS
- $companyUserStmt = $conn->prepare('SELECT * from `company_user` where sync = :sync and id_company = :id_company');
- $companyUserStmt->bindValue(':sync', 'never');
- $companyUserStmt->bindValue(':id_company', $companyId);
- $companyUserStmt->execute();
- $companyUser = $companyUserStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['company_user'] = $companyUser;
- //BUSCA PELAS CONFIGURAÇÕES DAS EMPRESAS
- $configStmt = $conn->prepare('SELECT * from `config` where sync = :sync and id_company = :id_company');
- $configStmt->bindValue(':sync', 'never');
- $configStmt->bindValue(':id_company', $companyId);
- $configStmt->execute();
- $config = $configStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['config'] = $config;
- //BUSCA PELOS TIPOS DE MENU
- $menuStmt = $conn->prepare('SELECT * from `menu_type` where sync = :sync and id_company = :id_company');
- $menuStmt->bindValue(':sync', 'never');
- $menuStmt->bindValue(':id_company', $companyId);
- $menuStmt->execute();
- $menu = $menuStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['menu'] = $menu;
- //BUSCA PELAS PREFERÊNCIAS
- $preferenceStmt = $conn->prepare('SELECT * from `preference` where sync = :sync and id_company = :id_company');
- $preferenceStmt->bindValue(':sync', 'never');
- $preferenceStmt->bindValue(':id_company', $companyId);
- $preferenceStmt->execute();
- $preference = $preferenceStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['preference'] = $preference;
- //BUSCA PELAS CATEGORIAS DAS PREFERÊNCIAS
- $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');
- $preferenceCategoryStmt->bindValue(':sync', 'never');
- $preferenceCategoryStmt->bindValue(':id_company', $companyId);
- $preferenceCategoryStmt->execute();
- $preference_category = $preferenceCategoryStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['preference_category'] = $preference_category;
- //BUSCA PELOS ITENS DAS PREFERÊNCIAS
- $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');
- $preferenceItems->bindValue(':sync', 'never');
- $preferenceItems->bindValue(':id_company', $companyId);
- $preferenceItems->execute();
- $preference_item = $preferenceItems->fetchAll(PDO::FETCH_ASSOC);
- $list['preference_item'] = $preference_item;
- //BUSCA PELOS PRODUTOS
- $productsStmt = $conn->prepare('SELECT * from `product` where sync = :sync and id_company = :id_company');
- $productsStmt->bindValue(':sync', 'never');
- $productsStmt->bindValue(':id_company', $companyId);
- $productsStmt->execute();
- $products = $productsStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['products'] = $products;
- //BUSCA PELOS ADICIONAIS DOS PRODUTOS
- $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');
- $produtsAdditionalStmt->bindValue(':sync', 'never');
- $produtsAdditionalStmt->bindValue(':id_company', $companyId);
- $produtsAdditionalStmt->execute();
- $product_additionals = $produtsAdditionalStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['product_additionals'] = $product_additionals;
- //BUSCA PELOS PLANOS DAS EMPRESAS
- $companyPlanStmt = $conn->prepare('SELECT * from `company_plan_type`');
- $companyPlanStmt->execute();
- $plantType = $companyPlanStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['company_plan_type'] = $plantType;
- //BUSCA PELAS CATEGORIAS DOS PRODUTOS
- $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');
- $productsCategoryStmt->bindValue(':sync', 'never');
- $productsCategoryStmt->bindValue(':id_company', $companyId);
- $productsCategoryStmt->execute();
- $product_category = $productsCategoryStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['product_category'] = $product_category;
- //TODOS OS REGISTROS DE LOG
- $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');
- $localLogStmt->bindValue(':id_company', $companyId);
- $localLogStmt->bindValue('sync', 'never');
- $localLogStmt->execute();
- $logList = $localLogStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['company_log'] = $logList;
- //BUSCA PELAS IMAGENS DOS PRODUTOS
- $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');
- $productImages->bindValue(':sync', 'never');
- $productImages->bindValue(':id_company', $companyId);
- $productImages->execute();
- $product_image = $productImages->fetchAll(PDO::FETCH_ASSOC);
- $list['product_image'] = $product_image;
- //BUSCA PELAS EXIBIÇÕES DOS PRODUTOS
- $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');
- $productsExibitionStmt->bindValue(':id_company', $companyId);
- $productsExibitionStmt->bindValue(':sync', 'never');
- $productsExibitionStmt->execute();
- $product_exibition = $productsExibitionStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['product_exibition'] = $product_exibition;
- //BUSCA PELAS PREFERÊNCIAS DOS PRODUTOS
- $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');
- $productPreference->bindValue(':sync', 'never');
- $productPreference->bindValue(':id_company', $companyId);
- $productPreference->execute();
- $product_preference = $productPreference->fetchAll(PDO::FETCH_ASSOC);
- $list['product_preference'] = $product_preference;
- //BUSCA PELAS VENDAS DOS PRODUTOS
- $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');
- $productSales->bindValue(':sync', 'never');
- $productSales->bindValue(':id_company', $companyId);
- $productSales->execute();
- $product_sales = $productSales->fetchAll(PDO::FETCH_ASSOC);
- $list['product_sales'] = $product_sales;
- //BUSCA PELAS TAGS DOS PRODUTOS
- $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');
- $productTags->bindValue(':sync', 'never');
- $productTags->bindValue(':id_company', $companyId);
- $productTags->execute();
- $product_tags = $productTags->fetchAll(PDO::FETCH_ASSOC);
- $list['product_tags'] = $product_tags;
- //BUSCA PELOS TIPOS DOS PRODUTOS
- $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');
- $productType->bindValue(':sync', 'never');
- $productType->bindValue(':id_company', $companyId);
- $productType->execute();
- $product_types = $productType->fetchAll(PDO::FETCH_ASSOC);
- $list['product_types'] = $product_types;
- //BUSCA PELOS TIPOS De VENDAS
- $saleType = $conn->prepare('SELECT * from `sale_type` where sync = :sync and id_company = :id_company');
- $saleType->bindValue(':sync', 'never');
- $saleType->bindValue(':id_company', $companyId);
- $saleType->execute();
- $sale_type = $saleType->fetchAll(PDO::FETCH_ASSOC);
- $list['sale_type'] = $sale_type;
- //BUSCA PELAS MESAS
- $tableStmt = $conn->prepare('SELECT * from `table` where sync = :sync and id_company = :id_company');
- $tableStmt->bindValue(':sync', 'never');
- $tableStmt->bindValue(':id_company', $companyId);
- $tableStmt->execute();
- $table = $tableStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['table'] = $table;
- //BUSCA PELAS MESAS
- $tagStmt = $conn->prepare('SELECT * from `tag` where sync = :sync ');
- $tagStmt->bindValue(':sync', 'never');
- $tagStmt->execute();
- $tag = $tagStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['tag'] = $tag;
- //BUSCA PELAS TIPOS DE AUDIÊNCIAS
- $target = $conn->prepare('SELECT * from `target_audience` where sync = :sync and id_company = :id_company');
- $target->bindValue(':sync', 'never');
- $target->bindValue(':id_company', $companyId);
- $target->execute();
- $targetAudience = $target->fetchAll(PDO::FETCH_ASSOC);
- $list['target'] = $targetAudience;
- //BUSCA PELOS COMBOS
- $comboStmt = $conn->prepare('SELECT * from `combo` where sync = :sync and id_company = :id_company');
- $comboStmt->bindValue(':sync', 'never');
- $comboStmt->bindValue(':id_company', $companyId);
- $comboStmt->execute();
- $combo = $comboStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['combo'] = $combo;
- //BUSCA PELOS COMBOS
- $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');
- $comboGroup->bindValue(':sync', 'never');
- $comboGroup->bindValue(':id_company', $companyId);
- $comboGroup->execute();
- $combo = $comboGroup->fetchAll(PDO::FETCH_ASSOC);
- $list['combo_group'] = $combo;
- //BUSCA PELOS COMBOS
- $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');
- $comboGroupItem->bindValue(':sync', 'never');
- $comboGroupItem->bindValue(':id_company', $companyId);
- $comboGroupItem->execute();
- $combo = $comboGroupItem->fetchAll(PDO::FETCH_ASSOC);
- $list['combo_group_item'] = $combo;
- //BUSCA PELOS COMBOS
- $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');
- $comboType->bindValue(':sync', 'never');
- $comboType->bindValue(':id_company', $companyId);
- $comboType->execute();
- $combo = $comboType->fetchAll(PDO::FETCH_ASSOC);
- $list['combo_type'] = $combo;
- //BUSCA PELOS COMBOS
- $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');
- $comboExibition->bindValue(':sync', 'never');
- $comboExibition->bindValue(':id_company', $companyId);
- $comboExibition->execute();
- $combo = $comboExibition->fetchAll(PDO::FETCH_ASSOC);
- $list['combo_exibition'] = $combo;
- //BUSCA PELAS IMAGENS DOS COMBOS
- $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');
- $comboImage->bindValue(':sync', 'never');
- $comboImage->bindValue(':id_company', $companyId);
- $comboImage->execute();
- $combo = $comboImage->fetchAll(PDO::FETCH_ASSOC);
- $list['combo_image'] = $combo;
- //BUSCA PELAS CAMPANHAS
- $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) ');
- $campaignStmt->bindValue(':sync', 'never');
- $campaignStmt->bindValue(':company_id', $companyId);
- $campaignStmt->execute();
- $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['campaign'] = $campaign;
- //BUSCA PELAS EMPRESAS PARA INSERIR AS CAMPANHAS
- $campaignStmt = $conn->prepare('SELECT * from campaign_company where id_company = :company_id and sync = :sync');
- $campaignStmt->bindValue(':sync', 'never');
- $campaignStmt->bindValue(':company_id', $companyId);
- $campaignStmt->execute();
- $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['campaign_company'] = $campaign;
- //BUSCA PELAS campanhas de empresas
- $campaignStmt = $conn->prepare('SELECT * from restaurant_campaign where id_company = :company_id and sync = :sync');
- $campaignStmt->bindValue(':sync', 'never');
- $campaignStmt->bindValue(':company_id', $companyId);
- $campaignStmt->execute();
- $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['restaurant_campaign'] = $campaign;
- //BUSCA PELAS PRODUTOS CADASTRADOS EM CAMPANHAS DE EMPRESAS
- $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');
- $campaignStmt->bindValue(':sync', 'never');
- $campaignStmt->bindValue(':company_id', $companyId);
- $campaignStmt->execute();
- $campaign = $campaignStmt->fetchAll(PDO::FETCH_ASSOC);
- $list['restaurant_campaign_product'] = $campaign;
- $list['error'] = false;
- $conn->commit();
- return $list;
- }
- catch (Exception $e) {
- $list['error'] = true;
- $conn->rollBack();
- return $list;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement