Untitled
unknown
plain_text
a year ago
18 kB
3
Indexable
<?php include("koneksi.php"); if ($_SERVER['REQUEST_METHOD'] == 'POST') { $company = $_POST['company']; $geturl = $_POST['geturl']; $datampos = $_POST['datampos']; $jsonData = $_POST['datampos']; $logFile = fopen("logfile.txt", "a"); // Open or create loginfo.txt in append mode ("a") if ($logFile) { $logEntry = date('Y-m-d H:i:s') . "Data: $jsonData" . PHP_EOL; fwrite($logFile, $logEntry); fclose($logFile); } else { error_log("Failed to open loginfo.txt for writing."); } $counter = 1; $data = json_decode($_POST['datampos'], true); try{ foreach ($data['data'] as $item) { $id = isset($item['id']) ? $item['id'] : ''; $documentno = isset($item['documentno']) ? $item['documentno'] : ''; $firstSixDigits = substr($documentno, 0, 6); $findid = "SELECT COALESCE((SELECT documentno FROM web.m_pos mp WHERE documentno like '%$firstSixDigits%' order by documentno desc limit 1), '0') AS documentno"; $go = pg_query($conn, $findid); $resultdoc = pg_fetch_assoc($go); if ($go) { if ($resultdoc['documentno'] != 0) { $noDok = $resultdoc['documentno']; $noDok++; } else { $noDok = $firstSixDigits . '00001'; } } else { } $inputString = $documentno; $lastDigits2 = substr($inputString, -4); $numericPart1 = (int)preg_replace('/[^0-9]/', '', $lastDigits2); $digitsrow = strlen((string)$numericPart1); if ($digitsrow == 1) { $digitsran = 6; } else if ($digitsrow == 2) { $digitsran = 8; } else if ($digitsrow == 3) { $digitsran = 9; } else if ($digitsrow == 4) { $digitsran = 11; } else { $digitsran = 12; } $hashedString = hash('sha256', $inputString); $hashedString20 = substr($hashedString, 0, 20); $encodedString = base64_encode(hex2bin($hashedString20)); $finalResult = substr($encodedString, 0, $digitsran); $finalResultUppercase = strtoupper($finalResult); $ranno = isset($item['ranno']) ? $item['ranno'] : ''; $dateordered = isset($item['dateordered']) ? $item['dateordered'] : ''; $bonmanual = isset($item['bonmanual']) ? $item['bonmanual'] : ''; $description = isset($item['description']) ? $item['description'] : ''; $trxtime = isset($item['trxtime']) ? $item['trxtime'] : ''; $syncedbi = isset($item['syncedbi']) ? $item['syncedbi'] : ''; $syncedadem = isset($item['syncedadem']) ? $item['syncedadem'] : ''; $warehouse_id = isset($item['warehouse_id']) ? $item['warehouse_id'] : ''; $cashier_id = isset($item['cashier_id']) ? $item['cashier_id'] : ''; $customer_id = isset($item['customer_id']) ? $item['customer_id'] : NULL; $gro_id = isset($item['gro_id']) ? $item['gro_id'] : ''; $guide_id = isset($item['guide_id']) ? $item['guide_id'] : ''; $created_at = isset($item['created_at']) ? $item['created_at'] : ''; $updated_at = isset($item['updated_at']) ? $item['updated_at'] : ''; $created_by = isset($item['created_by']) ? $item['created_by'] : ''; $updated_by = isset($item['updated_by']) ? $item['updated_by'] : ''; $kondisi_pos = isset($item['kondisi_pos']) ? $item['kondisi_pos'] : ''; $now = new DateTime(); $formattedDate = $now->format('Y-m-d'); list($year, $month, $day) = explode("-", $formattedDate); $year = substr($year, -2); if (strlen($month) == 1) { $month = "0" . $month; } if (strlen($day) == 1) { $day = "0" . $day; } $nodocumentexplode = $year . $month . $day; $dateTime = new DateTime($dateordered); $formattedDate = $dateTime->format('Y-m-d'); if ($kondisi_pos == 'void') { $sqlsatu = "INSERT INTO web.m_vpos (documentno,ranno,dateordered,bonmanual,description,trxtime,warehouse_id,cashier_id,customer_id,gro_id,guide_id,created_at,updated_at,created_by,updated_by) values ('$noDok', '$ranno', '$formattedDate', '$bonmanual', '$description', '$trxtime', '$syncedbi', '$syncedadem', '$warehouse_id', '$cashier_id', '0', '$gro_id', '$guide_id', 'now()', 'now()', '$cashier_id', '$cashier_id') RETURNING id,documentno"; $gom_pos = pg_query($conn, $sqlsatu); } else { $sqlsatu = "INSERT INTO web.m_pos (documentno, ranno, dateordered, bonmanual, description, trxtime, syncedbi, syncedadem, warehouse_id, cashier_id, customer_id, gro_id, guide_id, created_at, updated_at, created_by, updated_by) VALUES ('$noDok', '$ranno', ' $formattedDate', '$bonmanual', '$description', '$trxtime', '$syncedbi', '$syncedadem', '$warehouse_id', '$cashier_id', '0', '$gro_id', '$guide_id', 'now()', 'now()', '$cashier_id', '$cashier_id') RETURNING id, documentno"; $gom_pos = pg_query($conn, $sqlsatu); } if ($gom_pos) { if (pg_num_rows($gom_pos) > 0) { $insertedRow = pg_fetch_assoc($gom_pos); $lastPosId = $insertedRow['id']; $lastPosDoc = $insertedRow['documentno']; } else { } } else { } $rightmost4Digits = substr($lastPosDoc, -5); $findid = "SELECT COALESCE((SELECT documentno FROM web.m_fixpos WHERE documentno LIKE '%$firstSixDigits%' ORDER BY documentno DESC LIMIT 1), '0') AS documentno;"; $go = pg_query($conn, $findid); $result = pg_fetch_assoc($go); if ($go) { if ($result['documentno'] != 0) { $noDokfix = $result['documentno']; $noDokfix++; } else { $noDokfix = $firstSixDigits . '00001'; } } else { } if ($rightmost4Digits % 2 == 0) { } else { $sqlsatu = "INSERT INTO web.m_fixpos (documentno, dateordered, description, bonmanual, trxtime, ranno, warehouse_id, cashier_id, customer_id, gro_id, guide_id, syncpjk, created_at, updated_at, created_by, updated_by) VALUES ('$noDokfix','$formattedDate', '$description','$bonmanual','$trxtime','$ranno','$warehouse_id','$cashier_id',0,'$gro_id','$guide_id','N','now()', 'now()', '$cashier_id', '$cashier_id') RETURNING id, documentno"; $goresult = pg_query($conn, $sqlsatu); $resultdoc = pg_fetch_assoc($goresult); if ($goresult) { $idposfix = $resultdoc['id']; } } $billloop = 0; foreach ($item['data_m_pospayment'] as $payment) { $ptype = isset($payment['ptype']) ? $payment['ptype'] : ''; if ($ptype != 'C') { $billloop += isset($payment['bill']) ? $payment['bill'] : 0; } } foreach ($item['data_m_pospayment'] as $payment) { $id = isset($payment['id']) ? $payment['id'] : ''; $invoicedamt = isset($payment['invoicedamt']) ? $payment['invoicedamt'] : ''; $payamt = isset($payment['payamt']) ? $payment['payamt'] : ''; $bill = isset($payment['bill']) ? $payment['bill'] : ''; $ptype = isset($payment['ptype']) ? $payment['ptype'] : ''; if ($ptype == 'C') { $changeamt = isset($payment['changeamt']) ? $payment['changeamt'] : ''; $totalbill = $billloop - $payamt; $changeamt = $bill - $totalbill; } else { $changeamt = 0; $totalbill = $bill; } $edc_id = isset($payment['edc_id']) ? $payment['edc_id'] : 0; $card_id = isset($payment['card_id']) ? $payment['card_id'] : ''; $cardnumber = isset($payment['cardnumber']) ? $payment['cardnumber'] : 0; $cardname = isset($payment['cardname']) ? $payment['cardname'] : ''; $created_at = isset($payment['created_at']) ? $payment['created_at'] : ''; $updated_at = isset($payment['updated_at']) ? $payment['updated_at'] : ''; $created_by = isset($payment['created_by']) ? $payment['created_by'] : ''; $updated_by = isset($payment['updated_by']) ? $payment['updated_by'] : ''; $kondisi_pospayment = isset($payment['kondisi_pospayment']) ? $payment['kondisi_pospayment'] : ''; $now = new DateTime(); if ($payamt != '0') { if ($kondisi_pospayment == 'void') { $sqlsatu = pg_query($conn, "insert into web.m_vpospayment (pos_id, invoicedamt, payamt, changeamt, ptype, edc_id, card_id, cardnumber, cardname, trxtime, created_at, updated_at, created_by, updated_by) values ('$pos_id', '$invoicedamt', '$payamt', '$changeamt', '$ptype', '$edc_id', '$card_id', '$cardnumber', '$cardname', '$trxtime', '$trxtime', '$trxtime', '$cashier_id', '$cashier_id')"); $go = pg_query($conn, $sqlsatu); } else { $pos_id = isset($lastPosId) ? $lastPosId : ''; $created_by = !empty($created_by) ? (int)$created_by : 0; $updated_by = !empty($updated_by) ? (int)$updated_by : 0; $sqlsatu = "insert into web.m_pospayment (pos_id, bill, payamt, changeamt, ptype, edc_id, card_id, cardnumber, cardname, trxtime, created_at, updated_at, created_by, updated_by) values ($pos_id, $totalbill, $bill, $changeamt, '$ptype', $edc_id, 0, '$cardnumber', '$cardname', '$trxtime', '$trxtime', '$trxtime', '$cashier_id', '$cashier_id')"; $go = pg_query($conn, $sqlsatu); if ($rightmost4Digits % 2 == 0) { } else { $sqlsatu = "INSERT INTO web.m_fixpospayment (pos_id, bill, payamt, changeamt, ptype, edc_id, card_id, cardnumber, cardname, trxtime, created_at, updated_at, created_by, updated_by) values ($idposfix, $bill, $payamt, $changeamt, '$ptype', $edc_id, $card_id, '$cardnumber', '$cardname', '$trxtime', '$trxtime', '$trxtime', '$cashier_id', '$cashier_id')"; $goresult = pg_query($conn, $sqlsatu); } if ($go) { } else { } } } else { } } foreach ($item['data_mposline'] as $posline) { $id = isset($posline['id']) ? $posline['id'] : ''; $pos_id = isset($lastPosId) ? $lastPosId : ''; $promo_id = isset($posline['promo_id']) ? $posline['promo_id'] : ''; $promoline_id = isset($posline['promoline_id']) ? $posline['promoline_id'] : ''; $product_id = isset($posline['product_id']) ? $posline['product_id'] : ''; $qty = isset($posline['qty']) ? $posline['qty'] : ''; $discount = isset($posline['discount']) ? $posline['discount'] : ''; $price = isset($posline['price']) ? $posline['price'] : ''; $taxamt = NULL; $discountamt = NULL; $pricelist = isset($posline['pricelist']) ? $posline['pricelist'] : ''; $applicable = isset($posline['applicable']) ? $posline['applicable'] : ''; $trxtime = isset($posline['trxtime']) ? $posline['trxtime'] : ''; $created_at = isset($posline['created_at']) ? $posline['created_at'] : ''; $updated_at = isset($posline['updated_at']) ? $posline['updated_at'] : ''; $created_by = isset($posline['created_by']) ? $posline['created_by'] : ''; $updated_by = isset($posline['updated_by']) ? $posline['updated_by'] : ''; $kondisi_posline = isset($posline['kondisi_posline']) ? $posline['kondisi_posline'] : ''; $m_pos_treatment = isset($posline['m_pos_treatment']) ? $posline['m_pos_treatment'] : ''; $terapis_id = isset($posline['terapis_id']) ? $posline['terapis_id'] : 0; $room_id = isset($posline['room_id']) ? $posline['room_id'] : 0; if ($kondisi_posline == 'void') { $sqlsatu = "INSERT INTO web.m_vposline (pos_id, product_id, qty, price, taxamt, discountamt, trxtime, created_at, updated_at, created_by, updated_by) values ('$pos_id', '$product_id', '$qty', '$price', '$taxamt', '$discountamt', '$trxtime', 'now()', 'now()', '$cashier_id', '$cashier_id') RETURNING id"; $go = pg_query($conn, $sqlsatu); if ($go) { $insertedRow = pg_fetch_assoc($go); $lastPosLineId = $insertedRow['id']; } else { } } else if ($kondisi_posline == 'voidpromo') { $sqlsatu = "insert into web.m_vposline (pos_id, product_id, qty, price, taxamt, discountamt, trxtime, created_at, updated_at, created_by, updated_by) values ('$pos_id', '$product_id', '$qty', '$price', '$taxamt', '$discountamt', '$trxtime', 'now()', 'now()', '$cashier_id', '$cashier_id') RETURNING id"; $go = pg_query($conn, $sqlsatu); if ($go) { $insertedRow = pg_fetch_assoc($go); $lastPosLineId = $insertedRow['id']; } else { } $sqlsatu = "insert into web.m_vposline_promo (pos_id, posline_id, promo_id, promoline_id, qty, discount, discountamt, created_at, updated_at, created_by, updated_by) values ('$pos_id', '$posline_id', '$promo_id', '$promoline_id', '$qty', '$discount', '$discountamt','now()', 'now()', '$cashier_id', '$cashier_id') RETURNING id"; $go = pg_query($conn, $sqlsatu); } else if ($kondisi_posline == 'promo') { $sqlsatu = "insert into web.m_posline (pos_id, product_id, qty, price, taxamt, discountamt, trxtime, created_at, updated_at, created_by, updated_by) values ('$pos_id', '$product_id', '$qty', '$price', '$taxamt', '$discountamt', '$trxtime', 'now()', 'now()', '$cashier_id', '$cashier_id') RETURNING id"; $go = pg_query($conn, $sqlsatu); $sqlsatu = "insert into web.m_posline_promo ( pos_id, posline_id, promo_id, promoline_id, qty, discount, discountamt, created_at, updated_at, created_by, updated_by) values ('$pos_id', '$posline_id', '$promo_id', '$promoline_id', '$qty', '$discount', '$discountamt', 'now()', 'now()', '$cashier_id', '$cashier_id') RETURNING id"; $go = pg_query($conn, $sqlsatu); if ($go) { $insertedRow = pg_fetch_assoc($go); $lastPosLineId = $insertedRow['id']; } else { } } else { // if(){ $sqlsatu = "insert into web.m_posline (pos_id, product_id, qty, price, taxamt, discountamt, pricelist, trxtime, created_at, updated_at, created_by, updated_by) values ('$pos_id', '$product_id', '$qty', '$price', 0, 0, '$pricelist', '$trxtime', 'now()', 'now()', '$cashier_id', '$cashier_id') RETURNING id"; $go = pg_query($conn, $sqlsatu); if ($go) { $insertedRow = pg_fetch_assoc($go); $lastPosLineId = $insertedRow['id']; } else { } ///disini if ($rightmost4Digits % 2 == 0) { } else { $sqlsatu = "INSERT INTO web.m_fixposline (pos_id, product_id, qty, price, taxamt, discountamt, trxtime ,syncpjk , created_at, updated_at, created_by, updated_by) values ('$idposfix', '$product_id', '$qty', '$price', 0, 0, '$trxtime' ,'N' , 'now()', 'now()', '$cashier_id', '$cashier_id') RETURNING id"; $goresult = pg_query($conn, $sqlsatu); } //diisni } if ($m_pos_treatment == true) { if ($m_pos_treatment == 'void') { $sqlsatu = "insert into web.m_vpos_treatment (pos_id, posline_id, terapis_id, room_id, created_at, updated_at, created_by, updated_by) values ('$pos_id', '$lastPosLineId', '$terapis_id', '$room_id', 'now()', 'now()', '$cashier_id', '$cashier_id')"; $go = pg_query($conn, $sqlsatu); } else { $sqlsatu = "insert into web.m_pos_treatment (pos_id, posline_id, terapis_id, room_id, created_at, updated_at, created_by, updated_by) values ('$pos_id', '$lastPosLineId', '$terapis_id', '$room_id', 'now()', 'now()', '$cashier_id', '$cashier_id')"; $go = pg_query($conn, $sqlsatu); } } } } $response = [ "status" => 200, "message" => "Success connRetail", "access_token" => "asadaMMsnCAq28NGKqEf6jRueKLsf0wFnAcz2dOrPQF53GYS9AUzwWtiNFKQRniFb", ]; } catch (Exception $e) { // Handle the exception here $response = [ "status" => 404, "message" => "Gagal Kirim", "access_token" => "asadaMMsnCAq28NGKqEf6jRueKLsf0wFnAcz2dOrPQF53GYS9AUzwWtiNFKQRniFb", ]; echo 'Error: ' . $e->getMessage(); } header('Content-Type: application/json'); echo json_encode($response); }
Editor is loading...
Leave a Comment