<?php namespace myresto\controllers;use Yii;use yii\web\Controller;use myresto\models\SalesReturn;use myresto\models\SyncConfig;class SalesReturnController extends Controller{public function actionIndex(){$model=new SalesReturn();$tipe_tabel=$model->tipe_tabel;$conn=SyncConfig::getConnection();$config=SyncConfig::find()->where(['type_con'=>'resto'])->one();$access_token=$config->api_key;if(isset($_POST['date_start'])){$start=$_POST['date_start'];}else{$start='0000-00-00';}if(isset($_POST['jenis_sinkron'])){$jenis_sinkron=$_POST['jenis_sinkron'];}else{$jenis_sinkron='';}if(isset($_POST['date_end'])){$end=$_POST['date_end'];}else{$end='0000-00-00';}$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,$start,$end,$idHeaderLog);if($result!=NULL){$id_lokal=$result['sales_return']['custom_id'];$lastheader=$result['sales_return']['lastheader'];$response=$model->kirimData($result,$access_token);$simpan=$model->simpanStatus($response,$tipe_tabel,$id_lokal,$idHeaderLog,$lastheader,$jenis_sinkron);$echo=$simpan;}else{$result=$model->ambilData("reimport",$tipe_tabel,$start,$end,$idHeaderLog);if($result!=NULL){$id_lokal=$result['sales_return']['custom_id'];$lastheader=$result['sales_return']['lastheader'];unset($result['sales_return']['lastheader']);$response=$model->kirimData($result,$access_token);$simpan=$model->simpanStatus($response,$tipe_tabel,$id_lokal,$idHeaderLog,$lastheader,$jenis_sinkron);$echo=$simpan;}else{mysqli_query($conn,"UPDATE sync_data SET is_sync = '0' WHERE id_jurnal = '0' AND tipe_tabel = '$tipe_tabel'");$echo="ret_tran";}}return $echo;}}