หน้าเว็บ

วันอังคารที่ 28 พฤษภาคม พ.ศ. 2562

Axapta แก้ Batch ที่ End ไปแล้วให้กด ดู Dialog box ได้

Axapta แก้ Batch ที่ End ไปแล้วให้กด ดู Dialog box ได้
แก้ 2 ที่
1. Classes BatchStatusClass 
static BatchStatusClass construct(queueMap queue)
{
    switch (queue.TableId)
    {
        case tablenum(batch):
            switch (queue.status)
            {
                case BatchStatus::Hold:
                    return new BatchStatusHold(queue);
                    break;
                case BatchStatus::Waiting:
                    return new BatchStatusWaiting(queue);
                    break;
                case BatchStatus::Executing:
                    return new BatchStatusExecuting(queue);
                    break;
                case BatchStatus::Error:
                    return new BatchStatusError(queue);
                    break;
                case BatchStatus::Finished:
                    return new BatchStatusWaiting(queue);
                    //return new BatchStatusFinished(queue);
                    break;
                default:
                    throw error(strFmt("@SYS12580",queue.status));
            }
            break;

        case tablenum(gatewayQueue):
            switch (queue.status)
            {
                case BatchStatus::Hold:
                    return new BatchStatusHold(queue);
                case BatchStatus::Waiting:
                    return new BatchStatusWaiting(queue);
                case BatchStatus::Executing:
                    return new BatchStatusExecuting(queue);
                case BatchStatus::Error:
                    return new GatewayStatusError(queue);
                case BatchStatus::Finished:
                    return new BatchStatusWaiting(queue);
                    //return new GatewayStatusFinished(queue);
                default:
                    throw error(strFmt("@SYS12580",queue.status));
            }
            break;

    }

}

2. Form Bath เปิดปุ่มให้เป็น Enable

Axapta :: Axapta คำสั่งผลิต End ไม่ได้

Axapta :: Axapta คำสั่งผลิต End ไม่ได้
PD18-01456 : 378010712412 : SO18-460

ตรวจสอบพบ
1. มี Parts 901560712068 ไม่ถูกต้อง ใน Transaction ที่ PD เดียวกัน
2. Status ของ PD ไม่ถูกต้อง มีการ Reports และ UpCoseting ไปแล้วแต่ Status ยังเป็น Start อยู่

1. มี Parts 901560712068 ไม่ถูกต้อง ใน Transaction ที่ PD เดียวกัน ตรวจดูใน Picking List แล้วตัด Code 901560712068 ครบแล้ว
แต่ Transaction นี้เกินขึ้นมา
ทำให้ จะ Report ยอดเป็น 0 หรือ End คำสั่งผลิตมี Error ยอดของ Code ที่จะตัดไม่พอตามรูป

วิธีแก้
1.1.แก้ไขโดย ลบ Transaction ทิ้งที่ MS SQL Server ทิ้ง
  1. SELECT     *
  2. FROM         INVENTTRANS
  3. WHERE     (ITEMID = '901560712068') AND (TRANSREFID LIKE '%PD18-019456') 

1.2.Run Job recalcInventSum ใส่ Code ในข้อ 1. เข้าไป จะมีการ Update Onhand ให้ถูกต้อง
2. Status ของ PD ไม่ถูกต้อง มีการ Reports และ UpCoseting ไปแล้วแต่ Status ยังเป็น Start อยู่
ที่จริง Status ของ PD นี้ มีการ Reports และ Update Costing ไปแล้ว Status ที่ถูกต้องจะต้องเป็น
Status : Reported as finished
Remain Status : Costing
แต่ตามรูป Status ไม่ถูกต้องทำให้ End ไม่ได้
วิธีแก้
2.1. แก้ Status ของ PD ที่ MS SQL Server
  1. SELECT     *
  2. FROM         PRODTABLE
  3. WHERE     (PRODID LIKE '%PD18-019456')

แก้
ProdStatus จาก 4 ให้เป็น 5
BackOrderStatus จาก 1 ให้เป็น 4
Status ของ PD จะเปลี่ยนเป็นอันที่ถูกต้อง
2.2. Update คำสั่งผลิต ติ๊ก End และ ติ๊ก Reports
คำสั่งผลิตก็จะ End ให้

Axapta :: Error Post PO Invoice

Axapta :: Error Post PO Invoice
Error in unit of amount in currency 'US2'. Must be rounded to ' '.
Unit of 1,289.79 1,289.79 being posted to account '1110600' is too little.

เกิดจาก
- ค่าใน LineAmount มีทศนิยมมากเกินไป ต้องใส่แค่ 2 ตำแหน่ง

ค่าที่เห็นใน Line แสดง 2 ตำแหน่อง แต่ค่าจริง ๆ ใน Table มีทศนิยมมากกว่า 2 ตำแหน่งทำให้ Post Invoice ไม่ผ่านและ Error
แก้โดย Copy ค่าที่เป็น ใส่แทนค่าเดิม ทศนิยมก็จะหายไป

แก้โปรแกรม SetCourier ให้ปัดทศนิยมเป็น 2 ตำแหน่ง
แก้โปรแกรม
- ก่อนใส่ค่าลงใน Line Amount ให้ปัดทศนิยมให้เหลือ 2 ตำแหน่งก่อน
Code
  1. purchLineUpdate.LineAmount = DecRound(LineAmountSet, 2);

ค่าที่แสดงใน Line จะเห็นทศนิยมแค่ 2 ตำแหน่งแต่ค่าจริง ๆ ใน table ผ่าน MS SQL จะมีทศนิยมเยอะทำให้ Error

Home Assistant :: Server Switch ใช้กรณี ปิดเปิด Air Manual

Home Assistant :: Server Switch ใช้กรณี ปิดเปิด Air Manual เมื่อ MN-Server ไม่ทำงานหรือสั่งการไม่ได้ (สถานะต้องปิดไว้ถ้าเปิดจะเปิด 2 เครื่องพร้อมกัน)

http://192.168.2.200:8123/




มีไว้สำหรับปิด หรือ เปิด Air Manual เมื่อ MN-Server ไม่ทำงาน หรือสั่งงานไม่ได้
1. ROOM_A_ON_OFF (ไว้ปิดเปิด Air ตึกหน้า เปิดจะเปิดทั้งสองตัว เพราะมี PI เครื่องเดียว สั่ง GPI อันเดียว)
  1. nano /home/homeassistant/.homeassistant/configuration.yaml

  1.  - platform: mqtt
  2.     name: "ROOM_A_ON_OFF"
  3.     state_topic: "hass/state/ROOM_A_ON_OFF"
  4.     command_topic: "hass/cmd/ROOM_A_ON_OFF"
  5.     payload_on: "ON"
  6.     payload_of: "OFF"
  7.     retain: true

ใช้ Service ที่เครื่อง Raspberry PI ในการรับส่ง mqtt ชื่อ ROOM_A_ON_OFF
Code ที่เครื่อง PI
  1. nano /home/pi/mqttAir.py

  1.  
  2. #!/usr/bin/python
  3. # -*- coding: utf-8 -*-
  4.  
  5. # Copyright (c) 2010-2013 Roger Light <roger@atchoo.org>
  6. #
  7. # All rights reserved. This program and the accompanying materials
  8. # are made available under the terms of the Eclipse Distribution License v1.0
  9. # which accompanies this distribution.
  10. #
  11. # The Eclipse Distribution License is available at
  12. #   http://www.eclipse.org/org/documents/edl-v10.php.
  13. #
  14. # Contributors:
  15. #    Roger Light - initial implementation
  16. # Copyright (c) 2010,2011 Roger Light <roger@atchoo.org>
  17. # All rights reserved.
  18.  
  19. # This shows a simple example of an MQTT subscriber.
  20.  
  21. #import context  # Ensures paho is in PYTHONPATH
  22. import paho.mqtt.client as mqtt
  23.  
  24. ### PI ###
  25. import RPi.GPIO as GPIO                 #Add the GPIO library to a Python sketch
  26. import time                             #Add the time library to a Python sketch
  27. GPIO.setwarnings(False)
  28. GPIO.setmode(GPIO.BOARD)                #Setup GPIO using Board numbering
  29. GPIO.setup(16, GPIO.OUT)
  30.  
  31. ### Piface ###
  32. import pifacedigitalio
  33. pf = pifacedigitalio.PiFaceDigital()
  34.  
  35. def on_connect(mqttc, obj, flags, rc):
  36.     print("rc: " + str(rc))
  37.  
  38. def on_message(mqttc, obj, msg):
  39.     print(msg.topic + " " + str(msg.qos) + " " + str(msg.payload))
  40.     mqttc.publish("hass/state/ROOM_A_ON_OFF", str(msg.payload), 0, True)
  41. ## ON OFF ##
  42.    if str(msg.payload) == "ON":
  43.         #GPIO.output(16,GPIO.HIGH)
  44.         pf.relays[1].turn_on()
  45.         pf.relays[0].turn_on()
  46.     else:
  47.         pf.relays[1].turn_off()
  48.         pf.relays[0].turn_off()
  49.         #GPIO.output(16,GPIO.LOW)
  50.  
  51. def on_publish(mqttc, obj, mid):
  52.     print("mid: " + str(mid))
  53.  
  54. def on_subscribe(mqttc, obj, mid, granted_qos):
  55.     print("Subscribed: " + str(mid) + " " + str(granted_qos))
  56.  
  57. def on_log(mqttc, obj, level, string):
  58.     print(string)
  59.  
  60. # If you want to use a specific client id, use
  61. # mqttc = mqtt.Client("client-id")
  62. # but note that the client id must be unique on the broker. Leaving the client
  63. # id parameter empty will generate a random id for you.
  64. mqttc = mqtt.Client()
  65. mqttc.on_message = on_message
  66. mqttc.on_connect = on_connect
  67. mqttc.on_publish = on_publish
  68. mqttc.on_subscribe = on_subscribe
  69. # Uncomment to enable debug messages
  70. # mqttc.on_log = on_log
  71. mqttc.connect("192.168.2.200", 1883, 60)
  72. mqttc.subscribe("hass/cmd/ROOM_A_ON_OFF", 0)
  73.  
  74. mqttc.loop_forever()
  75.  
  76.  


Run เป็น Service
https://intranet.sci.com/blog.php?u=281&b=1583
Service
  1. sudo python /home/pi/mqttAir.py

ไว้รับคำสั่ง mqtt และสั่งเปิด Air ตาม Code

****** หมายเหตุ บางครั้งสั่งแล้วไม่ปิดไม่เปิด Service อาจจะค้าง ต้อง Restart Service ใหม่ หรือ Reboot เครื่อง PI ใหม่ *******

2. ROOM_B_ON_OFF (รอติดตั้ง ห้อง Server ตึกหลัง)

PHP :: Function แปลง Bytes เป็น MB, GB, KB

PHP :: Function แปลง Bytes เป็น MB, GB, KB

  1.  
  2. function formatSizeUnits($bytes)
  3. {
  4.     if($bytes >= 1073741824){
  5.     $bytes = number_format($bytes / 1073741824, 2) . ' GB';
  6.    } elseif($bytes >= 1048576){
  7.       $bytes = number_format($bytes / 1048576, 2) . ' MB';
  8.    } elseif ($bytes >= 1024){
  9.       $bytes = number_format($bytes / 1024, 2) . ' KB';
  10.    } elseif ($bytes > 1){
  11.       $bytes = $bytes . ' bytes';
  12.    } elseif ($bytes == 1){
  13.       $bytes = $bytes . ' byte';
  14.    } else {
  15.       $bytes = '-';
  16.    }
  17. return $bytes;
  18. }//Close Functions.
  19.  


ตัวอย่าง
https://intranet.sci.com/sci/CheckServer/check_start.php

https://stackoverflow.com/questions/5501427/php-filesize-mb-kb-conversion/5501447

Code Arduino ESP8266 SCI Smart Farm

Code Arduino ESP8266 SCI Smart Farm
- Connect Wifi
- อ่านค่าความชื้น
- ส่งค่า Home Assistant (192.168.0.202) --> Home Assistant ทำ Auto Scrip สั่งปิดเปิด SunOff อีกที

  1. #include <ESP8266WiFi.h>
  2. #include <PubSubClient.h>
  3.  
  4. // Update these with values suitable for your network.
  5. const char* ssid = "xxxxxx";
  6. const char* password = "xxxxxx";
  7. const char* mqtt_server = "192.168.2.202";
  8. int sensorPin = A0; // select the input pin for the potentiometer
  9. int sensorValue = 0; // variable to store the value coming from the sensor
  10.  
  11. WiFiClient espClient;
  12. PubSubClient client(espClient);
  13. long lastMsg = 0;
  14. char msg[50];
  15. int value = 0;
  16. char output;
  17. unsigned long seconds = 1000L; //Notice the L
  18. unsigned long minutes = seconds * 60;
  19.  
  20. void setup() {
  21.   pinMode(BUILTIN_LED, OUTPUT);     // Initialize the BUILTIN_LED pin as an output
  22.   Serial.begin(115200);
  23.   setup_wifi();
  24.   client.setServer(mqtt_server, 1883);
  25.   client.setCallback(callback);
  26.    
  27. }
  28.  
  29. void setup_wifi() {
  30.  
  31.   delay(10);
  32.   // We start by connecting to a WiFi network
  33.   Serial.println();
  34.   Serial.print("Connecting to ");
  35.   Serial.println(ssid);
  36.  
  37.   WiFi.begin(ssid, password);
  38.  
  39.   while (WiFi.status() != WL_CONNECTED) {
  40.     delay(500);
  41.     Serial.print(".");
  42.   }
  43.  
  44.   Serial.println("");
  45.   Serial.println("WiFi connected");
  46.   Serial.println("IP address: ");
  47.   Serial.println(WiFi.localIP());
  48. }
  49.  
  50. void callback(char* topic, byte* payload, unsigned int length) {
  51.   Serial.print("Message arrived [");
  52.   Serial.print(topic);
  53.   Serial.print("] ");
  54.   for (int i = 0; i < length; i++) {
  55.     Serial.print((char)payload[i]);
  56.   }
  57.   Serial.println();
  58.  
  59.   // Switch on the LED if an 1 was received as first character
  60.   if ((char)payload[0] == '1') {
  61.     digitalWrite(BUILTIN_LED, LOW);   // Turn the LED on (Note that LOW is the voltage level
  62.     // but actually the LED is on; this is because
  63.     // it is acive low on the ESP-01)
  64.   } else {
  65.     digitalWrite(BUILTIN_LED, HIGH);  // Turn the LED off by making the voltage HIGH
  66.   }
  67.  
  68. }
  69.  
  70. void reconnect() {
  71.  
  72.   // Loop until we're reconnected
  73.   while (!client.connected()) {
  74.     Serial.print("Attempting MQTT connection...");
  75.     // Attempt to connect
  76.     //client.connect(clientName, username, password )
  77.     if (client.connect("ESP8266Client","sci", "x1x2x3")) {
  78.       Serial.println("connected");
  79.       // Once connected, publish an announcement...
  80.       client.publish("outTopic", "connected MQTT");
  81.       // ... and resubscribe
  82.       client.subscribe("inTopic");
  83.     } else {
  84.       Serial.print("failed, rc=");
  85.       Serial.print(client.state());
  86.       Serial.println(" try again in 5 seconds");
  87.       // Wait 5 seconds before retrying
  88.       delay(5000);
  89.     }
  90.   }
  91. }
  92. void loop() {
  93.  
  94.   if (!client.connected()) {
  95.     reconnect();
  96.   }
  97.   client.loop();
  98.   // 1000 = 1s
  99.   //1 hour
  100.   //delay(60UL * 60UL * 1000UL);  //60 minutes each of 60 seconds each of 1000 milliseconds all unsigned longs
  101.   //delay(20000);
  102.  
  103.   long now = millis();
  104.   if (now - lastMsg > 3000) {
  105.     lastMsg = now;
  106.     //read the value from the sensor:
  107.     sensorValue = analogRead(sensorPin);
  108.     Serial.print("sensor = " );
  109.     Serial.println(sensorValue);
  110.     sprintf (msg,"%d", sensorValue);
  111.     client.publish("garden/moisture", msg);
  112.   }  
  113.  
  114. }

PHP : PHP Get Data From Axapta DB

PHP : PHP Get Data From Axapta DB
1. db.php
2. config.php
3. FileGet.php

1. db.php
<?php
class MysqlDB{
var $Host="";
var $User="";
var $Password="";
var $DB="";
var $ShowError="";
var $LinkID="";
var $Result="";
var $NumRows="";
var $NumFields="";

function MysqlDB($Host,$User,$Password,$DB,$ShowError){
    $this->Host=$Host;
    $this->User=$User;
    $this->Password=$Password;
    $this->DB=$DB;
    $this->ShowError=$ShowError;
    if($this->ShowError){
        error_reporting (E_ALL ^ E_NOTICE);
    }else{
        error_reporting (E_ALL ^ (E_NOTICE | E_WARNING));
    }
}

function Connect(){
    if(empty($this->LinkID)){
        $this->LinkID=@mysql_connect($this->Host,$this->User,$this->Password);
//        $this->Result=@mysql_db_query($this->DB,"SET NAMES tis620");
        if(empty($this->LinkID)){
            exit;
        }
    }
}

function Query($Sql){
    $this->Connect();
    @mysql_db_query($this->DB,"SET NAMES tis620");
    $this->Result=@mysql_db_query($this->DB,$Sql);
    $Error=mysql_error();
    if($Error and $this->ShowError){
        echo $Error."<br>".$Sql;
        exit;
    }
    $this->NumRows=mysql_num_rows($this->Result);
    $this->NumFields=mysql_num_fields($this->Result);
    return $this->NumRows;
}

function Update($Sql){
    $this->Connect();
    @mysql_db_query($this->DB,"SET NAMES tis620");
    @mysql_db_query($this->DB,$Sql);
    $Error=mysql_error();
    if($Error and $this->ShowError){
        echo $Error."<br>".$Sql;
        exit;
    }
}

function GetRow(){
    return mysql_fetch_array($this->Result);
}

function DataSeek($i){
    return mysql_data_seek($this->Result,$i);
}

function GetObject(){
    return mysql_fetch_object($this->Result);
}

function LastID(){
    return mysql_insert_id($this->LinkID);
}

function FieldName($FieldNumber){
    return mysql_field_name($this->Result,$FieldNumber);
}

}
?>

2. config.php
<?php
//MS SQL Config.
$MSServer = "xxxxx";
$MSUser = "xxx";
$MSPass = "xxxx";
$MSDB = "xxxxx";

//connection to the database
$dbhandle = mssql_connect($MSServer, $MSUser, $MSPass)
  or die("Couldn't connect to SQL Server on $MSServer");

//select a database to work with
$selected = mssql_select_db($MSDB, $dbhandle)
  or die("Couldn't open database ".$MSDB);
 
//MySQL Config. 
$Host="localhost";
$User="xxxxx";
$Password="xxxxx";
$DB="xxxx";
$ShowError=0;

?>
3. FileGet.php
<?php
    include_once("config.php");
    include_once("db.php");
   
    $myDB    = new MysqlDB($Host,$User,$Password,$DB,$ShowError);
    echo "Update Data From Axapta To Phpmyadmin.";

    //echo "<td align='center'>Update Data From Axapta To Phpmyadmin.</td>";

    $query  = "SELECT RefRecId, CONVERT(VARCHAR(10), TransDate, 120) AS TransDate, JournalId, CostAmount, AccountNum, AccountName, Department, Txt, CheckType";
    $query .= " FROM SCI_TmpMIToPhp ";
    //$query .= " WHERE purchLine.RecId = '".$RecId."' ";
    $result = mssql_query($query) or die("Couldn't query");
    $mssqlRows = mssql_num_rows($result);
    if($mssqlRows > 0){
        $row = mssql_fetch_array($result);
    }
    //mssql_free_result($result);
    //echo $row["JournalId"];
   
    //Loop display the results
    while($row = mssql_fetch_array($result))
    {
          //echo "<li>" . $row["JournalId"] . " : ". $row["TransDate"] ." : ". $row["Department"] ." : ". $row["ItemId"] ."</li>" ;
          //$TransDate = date_format($row["TransDate"], "Y-m-d");
          //$SQL .= " WHERE ( AccountNum = '1111000' OR AccountNum = '1111001' OR AccountNum = '1111200' OR AccountNum = '1111500')";
          $AccountNum = $row["AccountNum"];
          $Txt = $row["Txt"];
        if($AccountNum == 1111000 || $AccountNum == 1111001 || $AccountNum == 1111200 || $AccountNum == 11111500){
            $ItemId = substr($Txt, 0, 12);
            $LenTxt = strlen($Txt);
            $Txt = substr($Txt, 15, $LenTxt);          
        } else {
            $ItemId = "";
        }        
        
       $SQL = " INSERT INTO sci_consume_chart.Data (RefRecId, TransDate , JournalId, AccountNum, AccountName, ItemId, Txt, Amount, Department, CheckType)";
        $SQL.= " VALUES ('".$row["RefRecId"]."', '".$row["TransDate"]."', '".$row["JournalId"]."', '".$AccountNum."','".$row["AccountName"]."','".$ItemId."','".$Txt."','".$row["CostAmount"]."','".$row["Department"]."','".$row["CheckType"]."')";          
        //echo $SQL;
        $myDB->Update($SQL);
    }

    echo "<br><br><font color='green'> Update Data Finish. Please Close This Page.</font>";
?>