หน้าเว็บ

วันศุกร์ที่ 31 พฤษภาคม พ.ศ. 2562

Axapta :: Close Periods Axapta ทำให้ Ax เร็วขึ้น Inventsum ไม่คำนวณเยอะ

Axapta :: Close Periods Axapta ทำให้ Ax เร็วขึ้น Inventsum ไม่คำนวณเยอะ
** จะปิด Periods ใน Axapta สำคัญ **
1. ต้องสอบถาม งบง. ว่าทำฝั่งบัญชีเสร็จแล้วหรือยัง เพราะถ้าปิดไปแล้ว งบง. จะไม่สามารถปรับยอดหรือ Adjust ฝั่งบัญชีได้
2. วันที่ใน InventJournalTrans ต้องไม่มีค้าง ที่ยังไม่ได้ Post ต้องไม่มีในเดือนที่จะปิด
2.1. ค้างเปลี่ยนวันที่ใน Line และใส่ Remark นอกเล่มว่า งทส. เปลี่ยนวันที่
2.2. บางรายการมีการลบเล่มทิ้งแต่รายการใน Line ยังไม่อยู่ ต้องลบออก ไม่ได้ใช้งาน

1. Run Check ไม่มีการ Update แค่ดูเฉย ๆ
1.1. InventJournalTrans มีวันที่ที่จะ Close อยู่หรือไม่
1.2. InventJournalTrans มี แต่ InventJournalTable ไม่มี ถูกลบไป แต่ยังไม่ได้ Post
1.3. InventJournalTrans มี แต่ InventJournalTable ไปหาต่อที่ InventTrans ว่าถูก Post หรือไม่
Info ได้ Jouranl ออกมา ไปตรวจสอบ
  1. static void CheckCloseAC(Args _args)
  2. {
  3.     InventJournalTable      myInventJournalTable;
  4.     InventJournalTrans      myInventJournalTrans;
  5.     InventTrans             myInventTrans;
  6.  
  7.     LedgerJournalTrans      myLedgerJournalTrans;
  8.     LedgerJournalTable      myLegerJournalTable;
  9.     ;
  10.  
  11. ///// ###### Not Post. ####### ///////
  12.     WHILE
  13.     SELECT JournalId, TransDate FROM myInventJournalTrans
  14.     GROUP BY JournalId, TransDate
  15.     JOIN myInventJournalTable
  16.     WHERE myInventJournalTable.JournalId == myInventJournalTrans.JournalId
  17.         && myInventJournalTable.Posted == NoYes::No
  18.         && myInventJournalTrans.TransDate >= str2date("1/6/2015",123)
  19.         && myInventJournalTrans.TransDate <= str2date("31/6/2015",123)
  20.     {
  21.         info(strfmt("%1 : %2", myInventJournalTrans.JournalId, myInventJournalTrans.TransDate));
  22.     }
  23.  
  24. ///// ###### Delete Journal But InventJournalTrans remain data. ##########  /////
  25.     WHILE
  26.     SELECT JournalId, TransDate FROM myInventJournalTrans
  27.     GROUP BY JournalId, TransDate
  28.     WHERE myInventJournalTrans.TransDate >= str2date("1/6/2015",123)
  29.         && myInventJournalTrans.TransDate <= str2date("31/6/2015",123)
  30.     {
  31.         SELECT JournalId FROM myInventJournalTable
  32.         WHERE myInventJournalTable.JournalId == myInventJournalTrans.JournalId;
  33.         if(!myInventJournalTable.JournalId){
  34.             info(strfmt("%1 : %2", myInventJournalTrans.JournalId, myInventJournalTrans.TransDate));
  35.             //Check Post.
  36.             SELECT firstOnly myInventTrans
  37.             WHERE myInventTrans.TransRefId == myInventJournalTrans.JournalId;
  38.             if(!myInventTrans.TransRefId){
  39.                 info(myInventJournalTrans.JournalId);
  40.             }
  41.  
  42.         }
  43.     }
  44. }


2. เปลี่ยนวันที่ใน InventJournalTrans ให้เป็นวันที่ 1/1/2019 และแก้ Remark ( Update ข้อมูล เปลี่ยนวันที่ไปทีละเดือน Run ครั้งเดียว ถ้า Run ซ้ำ Remark จะเบิ้น)
  1. static void TWO_UpdateCloseAC(Args _args)
  2. {
  3.     InventJournalTable      myInventJournalTable;
  4.     InventJournalTrans      myInventJournalTransUpdate;
  5.     InventJournalTable      myInventJournalTableUpdate;
  6.     InventJournalTrans      myInventJournalTrans;
  7.     ;
  8.  
  9. /*    WHILE
  10.     SELECT * FROM myInventJournalTable
  11.     WHERE myInventJournalTable.Posted == NoYes::No
  12.         //&& myInventJournalTable.JournalId == "15-0003320"
  13.         && myInventJournalTable.TransDate >= str2date("1/3/2015",123)
  14.         && myInventJournalTable.TransDate <= str2date("31/3/2015",123)*/
  15.     WHILE
  16.     SELECT JournalId, TransDate FROM myInventJournalTrans
  17.     GROUP BY JournalId, TransDate
  18.     JOIN myInventJournalTable
  19.     WHERE myInventJournalTable.JournalId == myInventJournalTrans.JournalId
  20.         && myInventJournalTable.Posted == NoYes::No
  21.         && myInventJournalTrans.TransDate >= str2date("1/11/2018",123)
  22.         && myInventJournalTrans.TransDate <= str2date("31/11/2018",123)
  23.     {
  24.         myInventJournalTable = InventJournalTable::find(myInventJournalTrans.JournalId);
  25.         info(strfmt("%1", myInventJournalTable.JournalId));
  26.         ttsbegin;
  27.             WHILE
  28.             SELECT FORUPDATE myInventJournalTransUpdate
  29.             WHERE myInventJournalTransUpdate.JournalId == myInventJournalTable.JournalId
  30.             {   //### Update All Line To 1/1/2019 ####//
  31.                 myInventJournalTransUpdate.TransDate = str2date("1/1/2019", 123);
  32.                 myInventJournalTransUpdate.update();
  33.             }
  34.         ttscommit;
  35.  
  36.         //### Update InventTable ###//
  37.         ttsbegin;
  38.             SELECT FORUPDATE myInventJournalTableUpdate
  39.             WHERE myInventJournalTableUpdate.JournalId == myInventJournalTable.JournalId;
  40.                 //myInventJournalTableUpdate.TransDate = str2date("1/1/2019", 123);
  41.                 if(myInventJournalTable.Cause == ""){
  42.                      myInventJournalTableUpdate.Cause = strfmt("(งทส. เปลี่ยนวันที่ เดิม %1)", myInventJournalTable.TransDate);
  43.                 } else {
  44.                      myInventJournalTableUpdate.Cause = strfmt("%1 (งทส. เปลี่ยนวันที่ เดิม %2)", myInventJournalTable.Cause, myInventJournalTable.TransDate);
  45.                 }//Close If.
  46.                 myInventJournalTableUpdate.update();
  47.         ttscommit;
  48.  
  49.     }//Close While.
  50.  
  51.     info("Update Finish.");
  52. }


3. ทดลอง Close Periods ดู

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

VMware :: VMware Add Disk Formate And Add To Ubuntu

VMware :: VMware Add Disk Formate And Add To Ubuntu
ใช้ได้หลายวิธี
1. นำ Disk ไป Boot Gpart Disk
2. ใช้คำสั่ง Fdisk ยุ่งยาก
3. แบบง่าย ใช้คำสั่ง cfdisk
  1. fdisk -l
  1. cfdisk /dev/sdb1
ทำดังนี้
Delete
Create
Type
Write
Quit
4. formate เป็น ext4
  1. mkfs.ext4 /dev/sdb1

5. mount
  1. mount -t ext4 /dev/sdb1 /mnt


http://manpages.ubuntu.com/manpages/disco/man8/cfdisk.8.html

Zimbra :: Bash Backup Full Or increment .sh

Zimbra :: Bash Backup Full Or increment .sh

  1. echo "*******************************************************"
  2. echo "*     Zimbra - Backup all email accounts              *"
  3. echo "*******************************************************"
  4. Days=`date +%Y%m%d`;
  5. before="$(date +%s)"
  6.  
  7. cd /DATA/zimbra_backup
  8.  
  9. if [ $(date +%u) -eq '6' ]; then
  10.         rm sessions.txt
  11.         rm -r full*
  12.         rm -r inc*
  13.  
  14.         echo Start time of the full backup = $(date +%T)
  15.         su - zimbra -c "zmbkpose -f"
  16.         after="$(date +%s)"
  17.  
  18.         cp sessions.txt /DATA/zimbra_backup/BackupToQnap/
  19.         cp -r full-$Days* /DATA/zimbra_backup/BackupToQnap/
  20.  
  21.         #Zip File For Read Size Not Work. Full Disk#
  22.         #tar -pczf Zimbra_Full_$Days.tar.gz full-$Days* sessions.txt
  23.         #mv Zimbra_Ful_$Days.tar.gz /DATA/zimbra_backup/BackupToQnap/
  24.  
  25. #Old Code
  26.         #scp sessions.txt admin@192.168.0.218:/share/backup/
  27.         #scp -r full-$Days* admin@192.168.0.218:/share/backup/
  28.  
  29.         #scp sessions.txt admin@192.168.2.77:/share/Public/
  30.         #scp -r full-$Days* admin@192.168.2.77:/share/Public/
  31. else
  32.         echo Start time of the incremental backup = $(date +%T)
  33.         su - zimbra -c "zmbkpose -i"
  34.         after="$(date +%s)"
  35.  
  36.         tar -pczf Zimbra_Inc_$Days.tar.gz inc-$Days* sessions.txt
  37.         mv Zimbra_Inc_$Days.tar.gz /DATA/zimbra_backup/BackupToQnap/
  38.  
  39.         #cp sessions.txt /DATA/zimbra_backup/BackupToQnap/
  40.         #cp -r inc-$Days* /DATA/zimbra_backup/BackupToQnap/
  41.  
  42. #Old Code
  43.         #scp sessions.txt admin@192.168.0.218:/share/backup/
  44.         #scp -r inc-$Days* admin@192.168.0.218:/share/backup/
  45.  
  46.         #scp sessions.txt admin@192.168.2.77:/share/Public/
  47.         #scp -r inc-$Days* admin@192.168.2.77:/share/Public/
  48. fi
  49.  
  50. if [ $? -eq 0 ]; then
  51.     echo "*******************************************************"
  52.     echo "=== Transfer COMPLETED ==="
  53.     echo "*******************************************************"
  54. else
  55.     echo "*******************************************************"
  56.     echo "=== Transfer FAIL! ==="
  57.     echo "*******************************************************"
  58. fi
  59.  
  60. echo The process lasted = $(date +%T)
  61. # Calculating time
  62. elapsed="$(expr $after - $before)"
  63. hours=$(($elapsed / 3600))
  64. elapsed=$(($elapsed - $hours * 3600))
  65. minutes=$(($elapsed / 60))
  66. seconds=$(($elapsed - $minutes * 60))
  67. echo The complete backup lasted : "$hours hours $minutes minutes $seconds seconds"
  68. echo "****
***************************************************"

cronteb -e
  1. 10 21 * * 1-5 /DATA/zimbra_backup/autobackup.sh >> /DATA/zimbra_backup/autobackup.log 2>&1
  2. 00 18 * * 6  /DATA/zimbra_backup/autobackup.sh >> /DATA/zimbra_backup/autobackup.log 2>&1

PHP :: สร้างกราฟต่าง ๆ ด้วย PHP

PHP :: สร้างกราฟต่าง ๆ ด้วย PHP

ตัวอย่าง
https://intranet.sci.com/sci/AF/ConsumeChart/OT1.php?Year=2018

1. Download lib มาไว้ที่เครื่อง ที่ Run Web apache
https://www.highcharts.com/blog/download/

2. เข้าดูตัวอย่างใน examples จะมีตัวอย่างกราฟต่าง ๆ
PHP ตัวอย่าง เช่น
  1. <?php
  2. error_reporting(E_ERROR);
  3. define('IN_PHPBB', true);
  4. $phpbb_root_path = (defined('PHPBB_ROOT_PATH')) ? PHPBB_ROOT_PATH : '../../../';
  5. $phpEx = substr(strrchr(__FILE__, '.'), 1);
  6. include($phpbb_root_path . 'common.' . $phpEx);
  7.  
  8. include($phpbb_root_path ."sci/include/config.php");
  9. //include($phpbb_root_path ."sci/include/db.php");
  10. include($phpbb_root_path ."sci/include/functions.php");
  11. include($phpbb_root_path ."sci/include/db2.php");
  12.  
  13. $dep = array('DS', 'IF', 'OD', 'PD', 'QA', 'SS2', 'SS1:SS', 'SS1', 'PR', 'WH');
  14. $depTH = array('ฝอบ.', 'ฝทง.', 'ฝพอ.', 'ฝผล.', 'ฝปค.', 'ฝข.2', 'งสข.', 'ฝข.1', 'ฝวจ.', 'งคส.');
  15. //$SQL = "SELECT AccountNum,AccountName,SUM(AMOUNT),Department FROM sci_AxUsedWaste.Data";
  16.  
  17. $curYear = $_GET["Year"];
  18. if($curYear == ""){
  19.     $curYear = date("Y");
  20.     $yearLoop = array('2019', '2018', '2017');
  21. } else {
  22.     $yearLoop = array($curYear);
  23. }
  24.  
  25. ?>
  26. <!DOCTYPE HTML>
  27. <html>
  28.     <head>
  29.         <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  30.         <meta name="viewport" content="width=device-width, initial-scale=1">
  31.         <title>Highcharts Example</title>
  32.  
  33.         <style type="text/css">
  34.  
  35.         </style>
  36.     </head>
  37.     <body>
  38. <script src="../lib/code/highcharts.js"></script>
  39. <script src="../lib/code/modules/exporting.js"></script>
  40. <script src="../lib/code/modules/export-data.js"></script>
  41.  
  42. <!-- ---------------------------------------- 1 ------------------------------------------------------ --> 
  43. <div id="container" style="min-width: 310px; max-width: 1000px; margin: 0 auto"></div>
  44.  
  45.         <script type="text/javascript">
  46. Highcharts.setOptions({
  47.     lang: {
  48.       decimalPoint: '.',
  49.       thousandsSep: ','
  50.     }
  51. });
  52. var chart = new Highcharts.Chart({
  53.       chart: {
  54.          renderTo: 'container',
  55.          type: 'line'
  56.       },
  57.         title: {
  58.                 text: "กราฟแสดงจำนวน OT แยกฝ่าย"
  59.         },
  60.  
  61.         xAxis: {
  62.         categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  63.         max: 11
  64.         },
  65.  
  66.         yAxis: {
  67.         title: {
  68.             text: 'บาท'
  69.         }
  70.       },       
  71.         tooltip: {
  72.         crosshairs: true,
  73.         shared: true
  74.         },
  75.        
  76.         plotOptions: {
  77.         line: {
  78.             dataLabels: {
  79.                 enabled: true
  80.             },
  81.             marker: {
  82.                 radius: 4,
  83.                 lineColor: '#666666',
  84.                 lineWidth: 1
  85.             }
  86.         },
  87.         /*series: {
  88.             cursor: 'pointer',
  89.             point: {
  90.                 events: {
  91.                     click: function () {
  92.                         //alert('Category: ' + this.category + ', value: ' + this.y);
  93.                         location.href = 'consumeByMonth.php?acc=<?php echo $acc ?>' + '&mm=' + this.category + '&yy=' + <?php echo $curYear ?>;
  94.                     }
  95.                 }
  96.             }
  97.         }*/
  98.         },     
  99.         series: [
  100. <?php
  101.     for($i = 0; $i < 10; $i++ ){
  102.         $data = [];
  103.         $SQL = "SELECT * FROM sci_consume_chart.ot";
  104.         $SQL .= " WHERE YearMonth LIKE '$curYear-%'";
  105.         $SQL .= " AND Department LIKE '$depTH[$i]%'";
  106.         $SQL .= " ORDER BY Department";
  107.         $result = $mysqli->query($SQL);
  108. //      echo $SQL;
  109. //      exit;
  110.         while($row = $result->fetch_array()){
  111.             $data += [ $row["YearMonth"] => $row["OTCost"] ];
  112.         }
  113.        
  114.         for($n = 1; $n < date(m); $n++){
  115.             $date = sprintf($curYear."-%02s", $n);
  116.             if(!array_key_exists($date, $data)){
  117.                 $data += [ $date => 0 ];
  118.             }      
  119.         }
  120.         ksort($data);
  121. ?>         
  122.       {
  123.         name: <?php echo "'".$depTH[$i]."'" ?>,
  124.          data: [<?php echo join($data, ',') ?>]
  125.       },
  126. <?php
  127.     }
  128. ?>      
  129.       ]  
  130. });
  131.         </script>
  132.  
  133. <!-- --------------------------------------------- 2 ---------------------------------------------------- -->   
  134. <br>
  135. <br>       
  136.  
  137. <?php
  138. //############# Line 1 PD Weight ##################//
  139. $data1 = [];   
  140. $SQL = "SELECT * FROM sci_consume_chart.PD_weight";
  141. $SQL .= " WHERE YearMonth LIKE '$curYear-%'";
  142. $SQL .= " ORDER BY YearMonth";
  143. $result = $mysqli->query($SQL);
  144. while($row = $result->fetch_array()){
  145.     $data1 += [ $row["YearMonth"] => $row["Weight"] ];
  146. }
  147.  
  148. for($n = 1; $n <= 12; $n++){
  149.     $date = sprintf($curYear."-%02s", $n);
  150.     if(!array_key_exists($date, $data1)){
  151.         $data1 += [ $date => 0 ];
  152.     }      
  153. }
  154. ksort($data1);
  155. //print_r($dataColumn);    
  156.  
  157. //############# Line 2 OTHour ##################//
  158. for($i = 0; $i < 10; $i++ ){
  159.     $data2 = [];    //Reset.
  160.     $SQL = "SELECT SUM(OTHour) AS SumOTHour, YearMonth FROM sci_consume_chart.ot";
  161.     $SQL .= " WHERE YearMonth LIKE '$curYear-%'";
  162.     $SQL .= " GROUP BY YearMonth";
  163.     $SQL .= " ORDER BY Department";
  164.     $result = $mysqli->query($SQL);
  165.     while($row = $result->fetch_array()){
  166.         $data2 += [ $row["YearMonth"] => $row["SumOTHour"] ];
  167.     }
  168.    
  169.     for($n = 1; $n <= 12; $n++){
  170.         $date = sprintf($curYear."-%02s", $n);
  171.         if(!array_key_exists($date, $data2)){
  172.             $data2 += [ $date => 0 ];
  173.         }      
  174.     }
  175.     ksort($data2);
  176.    $data2 = join($data2, ',');
  177. }
  178.  
  179.  
  180. ?>
  181. <div id="container2" style="min-width: 310px; max-width: 1180px; margin: 0 auto"></div>
  182. <script type="text/javascript">
  183. var chart2 = new Highcharts.chart('container2', {
  184.     chart: {
  185.         zoomType: 'xy'
  186.     },
  187.     title: {
  188.         text: "กราฟแสดงน้ำหนักผลิต (กก.) และ OT (ชั่วโมง)"
  189.     },
  190.     subtitle: {
  191.         text: ''
  192.     },
  193.     xAxis: [{
  194.         categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun',
  195.             'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  196.         crosshair: true
  197.     }],
  198.     yAxis: [{ // Primary yAxis
  199.         labels: {
  200.             format: '{value} กิโลกรัม',
  201.             style: {
  202.                 color: Highcharts.getOptions().colors[1]
  203.             }
  204.         },
  205.         title: {
  206.             text: 'น้ำหนักผลิต',
  207.             style: {
  208.                 color: Highcharts.getOptions().colors[1]
  209.             }
  210.         },
  211.         opposite: true
  212.  
  213.     }, { // Secondary yAxis
  214.         gridLineWidth: 0,
  215.         title: {
  216.             text: 'OT',
  217.             style: {
  218.                 color: Highcharts.getOptions().colors[1]
  219.             }
  220.         },
  221.         labels: {
  222.             format: '{value} ชั่วโมง',
  223.             style: {
  224.                 color: Highcharts.getOptions().colors[1]
  225.             }
  226.         }
  227.     }],
  228.     tooltip: {
  229.         shared: true
  230.     },
  231.     legend: {
  232.           //layout: 'vertical', 
  233.         layout: 'horizontal',
  234.         align: 'left',
  235.         x: 100,
  236.         verticalAlign: 'top',
  237.         y: 20,
  238.         floating: true,
  239.         backgroundColor: (Highcharts.theme && Highcharts.theme.legendBackgroundColor) || 'rgba(255,255,255,0.25)'
  240.     },
  241.         plotOptions: {
  242.         column: {
  243.             dataLabels: {
  244.                 enabled: true,
  245.                 color: 'red'        
  246.             }
  247.         },
  248.         line: {
  249.             dataLabels: {
  250.                 enabled: true
  251.             },
  252.             marker: {
  253.                 radius: 4,
  254.                 lineColor: '#666666',
  255.                 lineWidth: 1
  256.             }
  257.         },/*
  258.         series: {
  259.             cursor: 'pointer',
  260.             point: {
  261.                 events: {
  262.                     click: function () {
  263.                         //alert('Category: ' + this.category + ', value: ' + this.y);
  264.                         location.href = 'TopItemByMonth.php?itemid=<?php echo $itemid ?>' + '&mm=' + this.category + '&yy=' + <?php echo $prvYear ?>;
  265.                     }
  266.                 }
  267.             }
  268.         }*/
  269.         },    
  270.     series: [{
  271.         name: 'น้ำหนักผลิต',
  272.         type: 'column',
  273.         data: [<?php echo join($data1, ',') ?>],
  274.         tooltip: {
  275.             valueSuffix: ' กิโลกรัม'
  276.         }
  277.  
  278.     }, {
  279.         name: 'Sum ทุกฝ่าย',
  280.         type: 'line',
  281.         yAxis: 1,
  282.         data: [<?php echo $data2; ?>],
  283.         tooltip: {
  284.             valueSuffix: ' บาท'
  285.         }
  286.                    
  287.     }]
  288. });
  289.  
  290. </script>   
  291. <br>
  292. <br>
  293. <!-- ---------------------------------------- 3 ------------------------------------------------------ --> 
  294. <div id="container3" style="min-width: 310px; max-width: 1000px; margin: 0 auto"></div>
  295.  
  296.         <script type="text/javascript">
  297. Highcharts.setOptions({
  298.     lang: {
  299.       decimalPoint: '.',
  300.       thousandsSep: ','
  301.     }
  302. });
  303. var chart3 = new Highcharts.Chart({
  304.       chart: {
  305.          renderTo: 'container3',
  306.          type: 'line'
  307.       },
  308.         title: {
  309.                 text: "กราฟแสดงอัตราส่วน OT/น้ำหนักผลิต (ชั่วโมง/ตัน)"
  310.         },
  311.  
  312.         xAxis: {
  313.         categories: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'],
  314.         max: 11
  315.         },
  316.  
  317.         yAxis: {
  318.         title: {
  319.             text: 'ชั่วโมง'
  320.         }
  321.       },       
  322.         tooltip: {
  323.         crosshairs: true,
  324.         shared: true
  325.         },
  326.        
  327.         plotOptions: {
  328.         line: {
  329.             dataLabels: {
  330.                 enabled: true
  331.             },
  332.             marker: {
  333.                 radius: 4,
  334.                 lineColor: '#666666',
  335.                 lineWidth: 1
  336.             }
  337.         },
  338.         /*series: {
  339.             cursor: 'pointer',
  340.             point: {
  341.                 events: {
  342.                     click: function () {
  343.                         //alert('Category: ' + this.category + ', value: ' + this.y);
  344.                         location.href = 'consumeByMonth.php?acc=<?php echo $acc ?>' + '&mm=' + this.category + '&yy=' + <?php echo $curYear ?>;
  345.                     }
  346.                 }
  347.             }
  348.         }*/
  349.         },     
  350.         series: [
  351. <?php
  352. if($curYear == date(Y)){
  353.     $loop = 3;
  354. } else {
  355.     $loop = 1;
  356. }   
  357.  
  358. for($i = 0; $i < $loop; $i++ ){
  359.     $data3 = [];
  360.     $SQL = "SELECT * FROM sci_consume_chart.PD_weight";
  361.     $SQL .= " WHERE YearMonth LIKE '$yearLoop[$i]-%'";
  362.     $SQL .= " ORDER BY YearMonth";
  363.     $result = $mysqli->query($SQL);
  364.     //$x = 1;
  365.     while($row = $result->fetch_array()){
  366.         //echo $x.":".$row["Weight"]."<br>";
  367.         $SQL2 = "SELECT SUM(OTHour) AS SumOTHour FROM sci_consume_chart.ot";
  368.         $SQL2 .= " WHERE YearMonth = '".$row["YearMonth"]."'";
  369.         $SQL2 .= " GROUP BY '".$row["YearMonth"]."'";
  370.         $result2 = $mysqli->query($SQL2);
  371.         //echo $SQL2."<br>";
  372.          
  373.         $row2 = $result2->fetch_array();
  374.         $ValuePrint = number_format($row2["SumOTHour"] / ($row["Weight"] / 1000), 2, ".", "");
  375.         $data3 += [ $row["YearMonth"] => $ValuePrint ];
  376.         //$x++; 
  377.     }
  378.    
  379.     if($curYear == $yearLoop[$i]){
  380.         for($n = 1; $n < date(m); $n++){
  381.             $date = sprintf($curYear."-%02s", $n);
  382.             if(!array_key_exists($date, $data3)){
  383.                 $data3 += [ $date => 0 ];
  384.             }      
  385.         }
  386.     }   
  387.     ksort($data3);
  388. ?>         
  389.       {
  390.         name: <?php echo "'".$yearLoop[$i]."'" ?>
  391.          data: [<?php echo join($data3, ',') ?>]
  392.       },
  393. <?php
  394. }
  395. ?>          
  396.       ]  
  397. });
  398.         </script>   
  399.        
  400.     </body>
  401. </html>

ติดตั้ง PHP5 ใน Ubuntu รุ่นหลัง ๆ เช่น Mint 17,18,19

 ติดตั้ง PHP5 ใน Ubuntu รุ่นหลัง ๆ เช่น Mint 17,18,19
1.Add Repository ใหม่
  1. add-apt-repository ppa:ondrej/apache2
  2. apt-get update
  3. apt-get upgrade
  4. add-apt-repository ppa:ondrej/php
  5. apt-get update

2.ติดตั้ง php 5.6
  1. apt-get install -y php5.6 php5.6-mcrypt php5.6-mbstring php5.6-curl php5.6-cli php5.6-mysql php5.6-gd php5.6-intl php5.6-xsl php5.6-zip libapache2-mod-php5.6

3.Enable/Disable module ที่ขัดกัน เช่น
  1. sudo a2dismod mpm_event
  2.  sudo a2enmod php5.6
  3.  sudo service apache2 restart

*ใช้ได้กับกรณีที่ติดตั้ง php หลาย version ด้วย เช่น
  1. sudo a2dismod php5.6 && sudo a2enmod php7.0 && sudo service apache2 restart
  2. sudo a2dismod php7.0 && sudo a2enmod php5.6 && sudo service apache2 restart

Zimbra Backup By zmbkpose

ใช้เครื่องมือช่วยคือ zmbkpose ตามแนบ
1.สร้าง folder สำหรับเก็บข้อมูล
  1. mkdir /opt/zimbra_backup

2.แตกไฟล์
  1. tar -zxvf Zmbkpose-1.0.5.tar.gz

3.จัดการ config file
  1. mkdir /etc/zmbkpose
  2. cp zmbkpose.conf /etc/zmbkpose/

แก้ zmbkpose.conf
  1. WORKDIR=/opt/zimbra_backup
  2. ADMINUSER=admin
  3. ADMINPASS=password
  4. LDAPMASTERSERVER=ldap://127.0.0.1:389
  5. LDAPZIMBRADN=uid=zimbra,cn=admins,cn=zimbra
  6. LDAPZIMBRAPASS=password #ใช้คำสั่ง zmlocalconfig -s zimbra_ldap_password เพื่อดู password
  7. LOGFILE=/opt/zimbra/log/backup.log
  8. PARALLEL_SUPPORT=0
  9. MAX_PARALLEL_PROCESS=3

4.ย้าย script ให้เรียกใช้สะดวก
  1. cp zmbkpose /usr/bin/

5.กำหนดสิทธิ
  1. chmod +x /usr/bin/zmbkpose
  2. chown zimbra:zimbra /opt/zimbra_backup

6.ติดตั้ง package ที่จำเป็นเพิ่ม
  1. apt-get install curl ldap-utils

7.สั่งให้ทำ full backup (ต้องเป็น root ก่อน)
  1. su - zimbra
  2. zmbkpose -f

8. restore Account ด้วยคำสั่ง
  1. zmbkpose -restoreAccount email1@sci.com, email2@sci.com

9.แสดงรายการที่ backup ไว้ด้วยคำสั่ง
  1. zmbkpose -l

10.restore ข้อมูลของ account ด้วยคำสั่ง
  1. zmbkpose -r email1@sci.com, email2@sci.com ชื่อรายการ backup #ที่ได้จาก -l เช่น full-20110214080105

9.คำสั่งอื่นให้พิมพ์ zmbkpose โดยไม่ใส่ parameter เพื่อดูรายละเอียด

Slack

api.slack.com
วิธีที่ 1 : สร้าง App
1.สร้าง APP : https://api.slack.com/slack-apps
2.สร้าง Bot : https://api.slack.com/apps/AF719989Z/bots?
3.สร้าง API Key : https://api.slack.com/apps/AF719989Z/oauth?

วิธีที่ 2 : สร้าง Custom Integration
1.เข้าไปที่ https://[YOUR_TEAM].slack.com/apps/build/custom-integration
2.เลือก Bots
3.Add bot integration จะได้ API Key

home assistant (https://www.home-assistant.io/components/notify.slack/)
1.แก้ไข configuration.yaml
  1. notify:
  2.   - name: ha_slack
  3.     platform: slack
  4.     api_key: จากขั้นตอนสร้าง Bot
  5.     default_channel: '#general'

2.restart home assistant
3.สร้าง script ทดสอบ
  1. '1546658960606':
  2.   alias: Test_Slack
  3.   sequence:
  4.   - data:
  5.       message: 'Strong room: {{ now ().year }}-{{ now ().month }}-{{ now ().day }}_{{
  6.         now ().hour }}-{{ now ().minute }}-{{ now ().second }}'
  7.       target:
  8.       - '#general'
  9.       title: Motion detected!
  10.     service: notify.ha_slack