<?php namespace myresto\models;use Yii;use yii\base\Model;use myresto\models\SyncConfig;class UpdateModifier extends Model{public $tipe_tabel="rst_menu_notes2";public function kirimData($data,$access_token){$id=$data['product']['custom_id'];$base=SyncConfig::$base;$curl=curl_init();curl_setopt_array($curl,array(CURLOPT_URL=>"https://$base.jurnal.id/core/api/v1/products/$id",CURLOPT_RETURNTRANSFER=>true,CURLOPT_CUSTOMREQUEST=>"PATCH",CURLOPT_POSTFIELDS=>json_encode($data),CURLOPT_HTTPHEADER=>array("apikey: $access_token","Content-Type: application/json")));$response=curl_exec($curl);curl_close($curl);return $response;}public function simpanStatus($data,$tipe_tabel,$id_lokal,$tgl,$idHeaderLog){$type_con=SyncConfig::$type_con;$conn=SyncConfig::getConnection();$berhasil=0;$data=json_decode($data,TRUE);$id_jurnal=0;if(isset($data['product']['id'])){$id_jurnal=$data['product']['id'];$status_sinkron="success";$ket="";$berhasil++;}else{$status_sinkron="failed";$ket=json_encode($data['error_full_messages']);$ket=addslashes($ket);}$query="INSERT INTO sync_to_jurnal (id_header, last_update, tipe_tabel, id_record, status_sinkron, keterangan, id_jurnal, tipe_proses, type_con) VALUES ('$idHeaderLog', '$tgl', '$tipe_tabel', '$id_lokal', '$status_sinkron', '$ket', '$id_jurnal', 'update', '$type_con')";mysqli_query($conn,$query);return $berhasil;}public function ambilData($tipe_tabel){$type_con=SyncConfig::$type_con;$conn=SyncConfig::getConnection('MyConnection');$connMyResto=SyncConfig::getConnection('MyResto');$dbNameMyConnection=SyncConfig::getDbNameMyConnection();$stmt=mysqli_query($conn,"SELECT last_update FROM sync_to_jurnal WHERE type_con = '$type_con' AND tipe_proses = 'update' ORDER BY last_update DESC LIMIT 1");$row=mysqli_fetch_assoc($stmt);if($row>0){$last_update=$row['last_update'];}else{$last_update="0000-00-00 00:00:00";}$result=array();$stmt=mysqli_query($connMyResto,"SELECT fpkey, fcode, fnotes, fprice, fdeleted, fmodifieddt
            FROM rst_menu_notes2 a
            JOIN $dbNameMyConnection.sync_to_jurnal b ON a.fpkey = b.id_record
            WHERE tipe_tabel = '$tipe_tabel' AND fmodifieddt > '$last_update' ORDER BY fmodifieddt ASC LIMIT 1");$row=mysqli_fetch_assoc($stmt);if($row>0){$del="";if($row['fdeleted']==1){$del="(Deleted)";}$result['product']['custom_id']="M".$row['fpkey'];$result['product']['last_update']=$row['fmodifieddt'];$result['product']['product_code']=$row['fcode'];$result['product']['name']=$row['fnotes'].$del;$result['product']['sell_price_per_unit']=$row['fprice'];$result['product']['taxable_sell']=true;$result['product']['is_sold']=true;$result['product']['track_inventory']="false";$result['product']['product_category_names'][0]="MODIFIER";}return $result;}}