<?php
namespace myresto\controllers;

use Yii;
use yii\web\Controller;
use myresto\models\UpdateProduct;
use myresto\models\SyncConfig;

class UpdateProductController extends Controller {
    public function actionIndex() {
        $model = new UpdateProduct();
        $tipe_tabel = $model->tipe_tabel;
        $conn = SyncConfig::getConnection();
        $config = SyncConfig::find()->where(['type_con' => 'resto'])->one();
        $access_token = $config->api_key;

        $idHeaderLog = $_POST['idHeaderLog'];

        $result = $model->ambilData($tipe_tabel);

        if ($result != NULL) {
            $response = $model->kirimData($result, $access_token);
            $simpan = $model->simpanStatus($response, $tipe_tabel, $id_lokal, $idHeaderLog);
            $echo = $simpan;
            // END - proses ambil, kirim dan simpan data yang baru
        } else {
            $echo = "upprod";
            // END - proses ambil, kirim dan simpan data yang gagal diimport
        }

        return $echo;
    }
}