<?php namespace myresto\controllers;use Yii;use yii\web\Controller;use myresto\models\ImportSupplier;use myresto\models\SyncConfig;class ImportSupplierController extends Controller{public function actionIndex(){$model=new ImportSupplier();$tipe_tabel=$model::$tipe_tabel;$conn=SyncConfig::getConnection();$config=SyncConfig::find()->where(['type_con'=>'resto'])->one();$access_token=$config->api_key;$idHeaderLog=$_POST['idHeaderLog'];$stmt=mysqli_query($conn,"SELECT id_header FROM sync_to_jurnal WHERE id_header < '$idHeaderLog' ORDER BY id_header DESC LIMIT 1");$row=mysqli_fetch_assoc($stmt);$lastheader=$row['id_header'];$result=$model->ambilData("import",$tipe_tabel);if($result!=NULL){for($i=0;$i<count($result['vendors']);$i++){$id_lokal[$i]=$result['vendors'][$i]['vendor']['id'];unset($result['vendors'][$i]['vendor']['id']);}$response=$model->kirimData($result,$access_token);$simpan=$model->simpanStatus($response,$tipe_tabel,$id_lokal,$idHeaderLog,$lastheader);$echo=$simpan;}else{$stmt=mysqli_query($conn,"SELECT * FROM sync_to_jurnal WHERE status_sinkron = 'proses' AND tipe_tabel = '$tipe_tabel'");if(mysqli_fetch_assoc($stmt)>0){$result=$model->ambilData("reimport",$tipe_tabel);for($i=0;$i<count($result['vendors']);$i++){$id_lokal[$i]=$result['vendors'][$i]['vendor']['id'];unset($result['vendors'][$i]['vendor']['id']);}$response=$model->kirimData($result,$access_token);$simpan=$model->simpanStatus($response,$tipe_tabel,$id_lokal,$idHeaderLog,$lastheader);$echo=$simpan;}else{mysqli_query($conn,"UPDATE sync_to_jurnal SET status_sinkron = 'proses' WHERE status_sinkron = 'failed' AND tipe_tabel = '$tipe_tabel' AND type_con = 'resto' AND id_header = '$idHeaderLog'");$echo="supp";}}return $echo;}}