<?php namespace myresto\controllers;use Yii;use yii\web\Controller;use myresto\models\ImportPayment;use myresto\models\SyncConfig;class ImportPaymentController extends Controller{public function actionIndex(){$model=new ImportPayment();$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['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,$access_token,$start,$end);if($result!=NULL){$jurnal_entry=$result['jurnal'];$pembulatan=$result['pembulatan'];$account=$result['method'];unset($result['jurnal']);unset($result['pembulatan']);unset($result['method']);$response=$model->kirimData($result,$access_token,'receive_payments/batch_create');$hasil=$jurnal_entry - $pembulatan;if($hasil<2){$model->kirimJurnalEntry($jurnal_entry,$result,$access_token,$account);}$simpan=$model->simpanStatus($response,$tipe_tabel,$idHeaderLog,$lastheader);$echo=$simpan;}else{$echo="pay";}return $echo;}}