4/09/2018

Axapta : Axapta คำสั่งผลิตทำ Jobcard แล้วเผลอติ๊ก Job Is Finish

Axapta : Axapta คำสั่งผลิตทำ Jobcard แล้วเผลอติ๊ก Job Is Finish ไปแต่ยังไม่ได้ End คำสั่งผลิต
ต้องการคีย์ ต้นทุน Jobcard เพิ่ม แต่คีย์ Jobcard ใหม่แล้วเขัาไปใน Line เลือก Job identification ไม่ได้

แก้โดย
- เข้าไปที่ Table ProdRouteJob
- หา ProdId ที่ตรงกับคำสั่งผลิตที่กำลังจะทำ
- แก้ JobStatus จาก End เป็น Start
เสร็จแล้วลองให้ ผลิตคีย์ Jobcard เพิ่ม เสร็จแล้วก็แก้กลับ จาก Start เป็น End

4/07/2018

Axapta : Axapta Marge Cell And Set Backgroud LibreOffice Calc

Axapta : Axapta Marge Cell And Set Backgroud LibreOffice Calc
Code :
                   strMarge = strfmt("A%1:J%1", rows + 1);
                    oRange = oSheet.getCellRangeByName(strMarge);
                    oRange.merge(true);
                    oRange.setPropertyValue("CellBackColor", 0x00dcff);
   
                    oRange = oSheet.getCellByPosition(0, rows);
                    oRange.SetString(strfmt("ÃÒ§ҹÂÍ´¢ÒÂã¹»ÃÐà·È ( %1 )", SalesGroupName));
   
                    strMarge = strfmt("A%1:J%1", rows + 2);
                    oRange = oSheet.getCellRangeByName(strMarge);
                    oRange.merge(true);
   
                    oRange = oSheet.getCellByPosition(0, rows + 1);
                    oRange.SetString(strfmt("From : %1 To : %2", fromDate, toDate));



Code : ALL
 
    static void openOffice(Args _args)
    {
        COM OpenOffice;
        COM oDeskTop;
        COM oDocument;
        COM oSheets;
        COM oSheet;
        COM oRange;
        COM BorderStruct;
        COMVariant arg;
        COMVariant byte;
        Array arr = new Array(Types::String);
        str url;
        int i;
    ;
        OpenOffice = new Com("com.sun.star.ServiceManager");
        oDeskTop = OpenOffice.CreateInstance("com.sun.star.frame.Desktop");
   
        // create and initialize a COMVariant object
        arg  = COMVariant::createFromArray(arr);
   
    //    url = "file:///C:/Losses.xls"; //open local file
    //    url = "file://Axaptaserver/AxaptaSP4/Excel/Losses.xls"; //open share file
    //    oDocument = oDeskTop.LoadComponentFromURL(url, "_blank", 0, arg);
        oDocument = oDeskTop.LoadComponentFromURL("private:factory/scalc", "_blank", 0, arg); //create new file
        oSheets   = oDocument.getSheets();
        oSheet    = oSheets.getByIndex(0); // select sheet
   
        BorderStruct = OpenOffice.Bridge_GetStruct('com.sun.star.table.BorderLine');
        BorderStruct.Color(24567057);
        BorderStruct.LineDistance(0);
        BorderStruct.InnerLineWidth(0);
        BorderStruct.OuterLineWidth(1);
   
    //    oRange = oSheet.getCellByPosition(8,1,9,1);
        oRange = oSheet.getCellRangeByName("H2:I2"); //ทำงานกับ range
        oRange.merge(true); // สั่ง merge ได้ด้วย
        oRange.setPropertyValue("CellBackColor", 16764057);
        oRange.SetPropertyValue("LeftBorder",BorderStruct);
        oRange.SetPropertyValue("RightBorder",BorderStruct);
        oRange.SetPropertyValue("TopBorder",BorderStruct);
        oRange.SetPropertyValue("BottomBorder",BorderStruct);
    //*****************************
        for(i=1; i<10;i++)
            {
            oRange = oSheet.getCellByPosition(0,i);
            oRange.SetValue(i); //ส่งข้อมูลจำพวกตัวเลข
            oRange.setPropertyValue("CellStyle", "Result");
            oRange = oSheet.getCellByPosition(1,i);
            oRange.Setstring('????????'); //ส่งข้อมูลประเภทตัวอักษร
            oRange.setPropertyValue('CharPosture',100);
            oRange = oSheet.getCellByPosition(2,i);
            oRange.SetValue(i*i);
            oRange.setPropertyValue('CharWeight',200);
            oRange.setPropertyValue('CharUnderline',124);
            oRange = oSheet.getCellByPosition(3,i);
            oRange.SetString(date2str(today(),123,2,2,2,2,4));
            oRange.setPropertyValue("CharColor", 500);
            oRange.setPropertyValue('CharShadowed', True);
            oRange = oSheet.getCellByPosition(4,i);
            oRange.SetString(today());
            oRange.setPropertyValue("CellBackColor", 0x99CCFF);
            oRange.setPropertyValue("CharHeight", 12);
            oRange.setPropertyValue("IsTextWrapped", True);
            oRange = oSheet.getCellByPosition(5,i);
            oRange.SetString(today());
            oRange.setPropertyValue("CellStyle", "Date");
            }
    }
    

4/06/2018

Owntracks : owntracks deleate User/Device

Owntracks : owntracks deleate User/Device
Delete List :
  1. cd /var/spool/owntracks/recorder/store/last/scivalve
  1. rm -r "name delete"


Delete DB : ข้อมูลจุด อยู่ใน .rce
  1. cd /var/spool/owntracks/recorder/store/rec/scivalve
  1. rm -r "name delete"


https://github.com/owntracks/recorder/issues/147

Axapta :: ใส่สี Control ใน Grid

Axapta :: ใส่สี Control ใน Grid

It is possible to use colours in grids on Axapta forms. This can be a useful method to highlight particular rows, or grid cells within a row, based on the data in the record.
Highlighting complete rows
The method .displayOption() method on a form datasource can be over-ridden to control the appearance of an single row in a grid. It is possible to set the background or foreground (text) colour. Since this is a form datasource method, the FormRowDisplayOption affects not only the grid, but also the other controls on this form connected to the datasource.

    public void displayOption(Common _record, FormRowDisplayOption _options)
    {
        _options.backColor(WinApi::RGB2int(255,0,0)); // red 
    }


Highlighting individual grid cells
To highlight one or more individual cells, use the ._options.affectedElementsByControl() method to limit the effect to only the cells in which you are interested.

Note that while this method can display the same colour in multiple cells, there is no way to display different colours in a single row.

    public void displayOption(Common _record, FormRowDisplayOption _options)
    {
        _options.backColor(WinApi::RGB2int(255,255,0)); // Yellow 
        _options.affectedElementsByControl(Control_Name.id());
        _options.affectedElementsByControl(Another_Control_Name.id());
    }

ต้องกำหนด Properties ใน Field ตรง AutoDeclaration เป็น Yes ด้วย
เช่น
public void displayOption(Common _record, FormRowDisplayOption _options)
{
    InventJournalTrans  myInventJournalTrans = _record;

    ;
    super(_record, _options);

    if(myInventJournalTrans.OrderQty != (myInventJournalTrans.Qty * -1)){
        _options.textColor(WinApi::RGB2int(255, 0, 0)); // Red
        _options.affectedElementsByControl(InventJournalTrans_Qty.id());
    }
}

http://www.axaptapedia.com/Using_colours_in_grids

4/04/2018

Axapta : Update ต้นทุนค่าแรงเมื่อเพิ่มเงินเดือนพนักงาน

ต้องทำใน Local ก่อน และ Backup ข้อมูลทั้ง Table ในของจริงก่อนจะเอาเข้า
1. Up แบบ Import File ทำไฟล์ แล้วเอาเข้ากรณีเพิ่มใหม่หรือยังไม่มี MC
https://intranet.sci.com/blog.php?u=578&b=1129

2. แบบมี ข้อมูลอยู่แล้วแต่ต้องการ Update ค่าแรง ใช้ Code ทำเป็น Job Run ทำไฟล์ โดยใช้ EmpId,ต้นทุนค่าแรง
Code

    static void UpdateCostcategoryOT(Args _args)
    {
            AsciiIO             myFile;
            AsciiIO             OKFile;
            AsciiIO             NOFile;
            int                 i,n;
            int                 intRecId;
            container           RecData;
            container           contTmp;
            ItemId              myMC;
            EmplId              myEmplId;
            Price               myCost;
            InventTable         inventTable;
            RouteCostCategory   routeCostCategory;
   
            ;
   
            myFile=new AsciiIO("D:\\2018_Update.csv","r");
            myfile.inFieldDelimiter(",");
            while(myFile.status() == IO_Status::Ok)
                RecData += myFile.read();
            myFile = null;
   
   
            OKFile=new AsciiIO("D:\\OK-Update.txt","a");
            NOFile=new AsciiIO("D:\\NO-Update.txt","a");
            for(i=1; i <= conlen(RecData); i++){
   
                myCost =  conpeek(RecData, i);
                i++;
                myEmplId =  conpeek(RecData, i);
   
                SELECT * FROM routeCostCategory
                WHERE routeCostCategory.EmplId == myEmplId;
   
                if(routeCostCategory.RecId){
                    //print(strfmt("%1 : %2 \t OK",i,myEmplId));
                    OKFile.write(strfmt("%1\t%2\t%3",myEmplId, routeCostCategory.CostPrice, myCost));
                    ttsbegin;
   
    // #####  Cost Amount ######
                    WHILE
                    SELECT FORUPDATE * FROM routeCostCategory
                    WHERE routeCostCategory.EmplId == myEmplId
                    {
                        routeCostCategory.CostPrice = myCost;
                        routeCostCategory.update();
                    }
    // #####  Cost Amount OT 1.5 ######
                    WHILE
                    SELECT FORUPDATE * FROM routeCostCategory
                    WHERE routeCostCategory.EmplId == myEmplId
                    && (routeCostCategory.CostCategoryId LIKE '*1.5' || routeCostCategory.CostCategoryId LIKE 'OT1.5*')
                    {
                        routeCostCategory.CostPrice = myCost * 1.5;
                        routeCostCategory.update();
                    }
    // #####  Cost Amount OT 2.0 ######
                    WHILE
                    SELECT FORUPDATE * FROM routeCostCategory
                    WHERE routeCostCategory.EmplId == myEmplId
                    && (routeCostCategory.CostCategoryId LIKE '*2.0' || routeCostCategory.CostCategoryId LIKE 'OT2.0*')
                    {
                        routeCostCategory.CostPrice = myCost * 2.0;
                        routeCostCategory.update();
                    }
    // #####  Cost Amount OT 3.0 ######
                    WHILE
                    SELECT FORUPDATE * FROM routeCostCategory
                    WHERE routeCostCategory.EmplId == myEmplId
                    && (routeCostCategory.CostCategoryId LIKE '*3.0' || routeCostCategory.CostCategoryId LIKE 'OT3.0*')
                    {
                        routeCostCategory.CostPrice = myCost * 3.0;
                        routeCostCategory.update();
                    }
                    ttscommit;
   
                }else{
                    //print(strfmt("%1 : %2 \t NO",i,myEmplId));
                    NoFile.write(strfmt("%1,%2",myEmplId, myCost));
                }
   
   
   
            }
            OKFile = null;
            NOFile = null;
            box::info(" Complete","File2SQL");
    //    pause;
   
    }



3. เปลี่ยนแท่นเปลี่ยนคน ต้องทำ
3.1. ได้ไฟล์มาทำไฟล์ เอารหัสพนักงานเข้าไป Check ว่ามีพนังานอยู่หรือไม่ ถ้าไม่มีตรวจสอบอาจใส่รหัสผิด หรือต้องเพิ่มข้อมูลใหม่ในข้อ 1.
ใช้ MC,EmpId
Code

    static void UpdateCostcategoryCheckMC(Args _args)
    {
            AsciiIO             myFile;
            AsciiIO             OKFile;
            AsciiIO             NOFile;
            int                 i,n;
            int                 intRecId;
            container           RecData;
            container           contTmp;
            ItemId              myMC;
            EmplId              myEmplId;
            Price               myCost;
            InventTable         inventTable;
            RouteCostCategory   routeCostCategory;
   
            ;
   
            myFile=new AsciiIO("D:\\CheckMC.csv","r");
            myfile.inFieldDelimiter(",");
            while(myFile.status() == IO_Status::Ok)
                RecData += myFile.read();
            myFile = null;
   
   
            OKFile=new AsciiIO("D:\\CheckMCOK.txt","a");
            NOFile=new AsciiIO("D:\\CheckMCNO.txt","a");
            for(i=1; i <= conlen(RecData); i++){
   
                myMC =  conpeek(RecData,i);
                i++;
                myEmplId =  conpeek(RecData,i);
   
                SELECT * FROM routeCostCategory
                WHERE routeCostCategory.CostCategoryId == myMC;
                if(routeCostCategory.RecId){
                    print(strfmt("%1 : %2 \t OK",i,myEmplId));
                    OKFile.write(strfmt("%1\t%2\t%3",myMC, myEmplId, routeCostCategory.EmplId));
                    /*ttsbegin;
                    WHILE SELECT FORUPDATE * FROM routeCostCategory
                    WHERE routeCostCategory.EmplId == myEmplId
                    {
                    routeCostCategory.CostPrice = myCost;
                    routeCostCategory.update();
                    }
                    ttscommit;*/
                }else{
                    print(strfmt("%1 : %2 \t NO",i,myEmplId));
                    NoFile.write(strfmt("%1,%2",myMC, myEmplId));
                }
   
   
   
            }
            OKFile = null;
            NOFile = null;
            box::info(" Complete","File2SQL");
    //    pause;
   
    }


3.2. ได้ไฟล์ที่จะ Update เปลี่ยนแท่น Format : MC,EmpId,EmpIdAX เขียน Code Update เปลี่ยนแท่น จะเปลี่ยนจาก Emp อีกคนเป็นอีกคน ทุก รายการที่ MC เดียวกัน แล้วค่อยไป Update ค่าแรงในข้อ 2.
Code    
    static void UpdateCostcategoryMC(Args _args)
    {
            AsciiIO             myFile;
            AsciiIO             OKFile;
            AsciiIO             NOFile;
            int                 i,n;
            int                 intRecId;
            container           RecData;
            container           contTmp;
            ItemId              myMC;
            ItemId              myMCUpdate;
            EmplId              myEmplId;
            EmplId              myEmplIdAX;
            Price               myCost;
            InventTable         inventTable;
            RouteCostCategory   routeCostCategory;
   
            ;
   
            myFile=new AsciiIO("D:\\UpdateMC.csv","r");
            myfile.inFieldDelimiter(",");
            while(myFile.status() == IO_Status::Ok)
                RecData += myFile.read();
            myFile = null;
   
            OKFile=new AsciiIO("D:\\UpdateMCOK.txt","a");
            NOFile=new AsciiIO("D:\\UpdateMCNO.txt","a");
            for(i=1; i <= conlen(RecData); i++){
   
                myMC = conpeek(RecData,i);
                i++;
                myEmplId =  conpeek(RecData,i);
                i++;
                myEmplIdAX =  conpeek(RecData,i);
   
                myMCUpdate = strfmt('*%1*', myMC);
                ttsbegin;
                WHILE
                SELECT FORUPDATE * FROM routeCostCategory
                WHERE routeCostCategory.EmplId == myEmplIdAX
                    && routeCostCategory.CostCategoryId LIKE myMCUpdate
                {
                    if(routeCostCategory.RecId){
   
                        //print(strfmt("%1 : %2 \t OK",i,myEmplId));
                        OKFile.write(strfmt("%1\t%2\t%3",myMC, myEmplId, myEmplIdAX));
   
                        routeCostCategory.EmplId = myEmplId;
                        routeCostCategory.update();
                    } else {
                        //print(strfmt("%1 : %2 \t NO",i,myEmplId));
                        NoFile.write(strfmt("%1,%2",myMC, myEmplId, myEmplIdAX));
                    }
                }
                ttscommit;
            }
            OKFile = null;
            NOFile = null;
            box::info(" Complete","File2SQL");
    //    pause;
   
    }



4.พนักงานออกไปแล้ว เขียน Code Reset รหัสและค่าแรง โดยเปลี่ยนรหัสพนักงาน
Code

    static void UpdateCostcategoryByEmpId(Args _args)
    {
            EmplId              myEmplId;
            Price               myCost;
            InventTable         inventTable;
            RouteCostCategory   routeCostCategory;
   
            ;
   
            ttsbegin;
                WHILE SELECT FORUPDATE * FROM routeCostCategory
                WHERE routeCostCategory.EmplId == '4273-5'
                {
                routeCostCategory.EmplId = '';
                routeCostCategory.CostPrice = 0;
                routeCostCategory.update();
                }
            ttscommit;
   
            box::info(" Complete","File2SQL");
    }