Wednesday, December 30, 2015

15 Pregnancy Power Foods

These healthy choices have the nutrients that you and your growing baby need.


You knew folate was important before conception and during your first few weeks of pregnancy, but your needs for the B vitamin stay high the whole nine months. Experts advise getting 400 micrograms per day through vitamin supplements or fortified foods (breakfast cereal is an easy way to do it, since many brands contain 400 micrograms per bowl), and another 200 micrograms through foods that are naturally high in folate, such as asparagus and black-eyed peas.

2. Dried Beans & Lentils

All women need 10 extra grams of protein a day during pregnancy (for a total of at least 60 grams); beans and lentils are an excellent source, with about 15 grams per cup. They're also high in fiber, which helps to combat constipation. And 1 cup of cooked lentils meets half of your daily folate requirement. "Add them to rice dishes and salads," suggests Lola O'Rourke, RD, spokesperson for the American Dietetic Association.

3. Broccoli

It's not only packed with nutrients that are necessary for a healthypregnancy -- such as calcium and folate -- but broccoli is also rich in fiber and disease-fighting antioxidants. And since it contains plenty of vitamin C, this popular green vegetable will help your body absorb iron when it's eaten with an iron-rich food, such as whole wheat pasta or brown rice.

4. Nonfat Milk

Your body absorbs roughly twice as much calcium from foods while you'repregnant, so your daily needs remain the same. But since most of us get too little calcium to begin with, drinking more nonfat milk is a smart move. Each 8-ounce glass supplies about 30 percent of the recommended dietary allowance of 1,000 milligrams.


5. Bananas

Bananas are rich in potassium and offer quick energy to fight off pregnancyfatigue. "They're also easy on your stomach if you're nauseated," says O'Rourke. Slice them up into cereal or whip one into a breakfast smoothie with yogurt, berries, ice, and a splash of orange juice.

6. Lean Meat

Your daily iron needs double during pregnancy, so it's important to include plenty of iron-rich foods now. "If you don't have good iron stores, you're more likely to feel tired," warns Jo Ann Hattner, RD, a dietitian in Palo Alto, California. Meat delivers a form of iron that's easily absorbed by your body.


7. Cheese

Soft cheeses are off-limits, but varieties such as cheddar and mozzarella can be a big help in meeting your calcium requirements -- each ounce contains between 150 and 200 milligrams. Cheese is also high in protein.

8. Eggs

Many women develop aversions to meat while pregnant. Eggs are an excellent alternative protein source, since they contain all the essential amino acids your body needs, says Hattner. There's nothing better for a quick dinner than an omelet with lots of chopped vegetables and a bit of cheese. If cooking aromas make you feel sick, hard-boil a batch of eggs to keep on hand in the refrigerator: Eat them whole for grab-and-go breakfasts and snacks, or chop them up into green salads.

9. Oatmeal

It's easy to get your day off to an energizing start by trading in your usual morning bagel or muffin for a bowl of oatmeal a few times a week. Why? Complex carbohydrates like oatmeal keep you satisfied longer, and the oat bran it contains can help lower your cholesterol levels. Instead of buying high-sugar flavored oatmeal, cook up the plain kind and swirl in a teaspoon or two of maple syrup or jelly.

10. Leafy Greens

Cooked spinach has high levels of folate and iron, and kale and turnip greens are both good calcium sources. Increase the nutrient value of your salads by passing up traditional iceberg in favor of darker-colored lettuces (the deep colors signal higher vitamin content). You can also add greens to a sandwich or stir them into soups and pasta dishes.

11. Whole-Grain Bread

By swapping your traditional white bread for a whole-grain variety, you can make sure you're consuming the recommended 20 to 35 daily grams of fiber (scan labels to find a loaf that offers at least 2 grams of fiber per slice). Whole-grain bread also supplies you with a good share of your iron and zinc.

12. Oranges

They're packed with vitamin C, folate, and fiber, and since they're nearly 90 percent water, they'll also help you meet your daily fluid needs (skimping on your fluid intake can leave you feeling fatigued).

13. Nuts & Nut Butters

Fat is critical for your baby's brain development and it also helps keep you fuller longer. Experts recommend replacing some saturated fats (such as those found in meat and butter) with unsaturated, a form of heart-healthy fat found in nuts. But because they are high in fat and calories, stick to 1-ounce servings of nuts and 2-tablespoon servings of nut butters. There is one caveat, however. If you have any sort of allergy, experts recommend that you avoid highly allergenic foods, such as peanuts, during your pregnancy; some data suggests that babies can be sensitized to certain foods in utero, raising their risk of food allergies later on in childhood.

14. Soy Foods

It's perfectly safe to follow your vegetarian eating plan while you'repregnant -- as long as you're diligent about getting necessary nutrients such as protein (your doctor or a dietitian can help you devise a healthy plan). So be sure to include foods like tofu, which packs 10 grams of protein per half cup.

15. Dried Fruit

It's a tasty, portable snack that's especially helpful when you're craving something sweet. Choose dried fruits such as apricots, cherries, and cranberries (which can also help to prevent urinary tract infections), but stay away from dried bananas, since they're processed in oil and loaded with fat.

Ax2012 specify the action for selected table's field being modified.

Below code is for specify the action for selected table's field after modified:-

public void modifiedField(FieldId _fieldId)
{
    super(_fieldId);

    switch (_fieldId)
    {
        case fieldNum(PayrollWorkerPositionEarningCode, EarningCode):

        if (PayrollEarningCode::find(this.EarningCode).QuantityUnit == PayrollQuantityUnit::Each)
        {
            this.CalculationFrequency = PayrollCalculationFrequency::findDefaultCalculationFrequency().RecId;
        }
        else
        {
            this.CalculationFrequency = 0;
        }

        break;
            
        case fieldNum(PayrollWorkerPositionEarningCode, Formula):

        if (PayrollEarningCode::find(this.EarningCode).QuantityUnit == PayrollQuantityUnit::Each)
        {
            this.CalculationFrequency = PayrollCalculationFrequency::findDefaultCalculationFrequency().RecId;
        }
        else
        {
            this.CalculationFrequency = 1;
        }

        break;
    }
}

Wednesday, August 19, 2015

Ax2012 Adding custom field to existing DMF

1. There a new fields in PurchLine:-

2.    Go to DMF table and add those fields manually

3.  Go to Query and find the DMF query. Restore the query
4.   If the customize field didn’t appear, backup the query.


5.     Delete the Data Sources

6.    Create the Data sources again

7.     Change the properties of the Fields to Yes for Dynamic

8.   Save and compile. 
9.   Go to Data import export framework > Setup > Target entities. 
10.  Create a new entity for purchline

11.  Click on Modify target mapping. 
12.  Those customize fields will be display out


13.   Go to Data import export framework > processing group. 
14.  Create a new processing group. 
15.  Click on the Generate source file and select those mapping field.

16. Done



Wednesday, July 22, 2015

Ax2012 Axapta select statement

Below is the code copy from blog : 

https://community.dynamics.com/ax/b/dynamicsaxhints/archive/2015/05/23/how-joins-in-x-select-statement-are-translated-into-t-sql

How joins in X++ select statement are translated into T-SQL

It is not always obvious what request is actually executed on SQL Server. The most confusing is probably exists join in X++. Let's analyze how joins in select statement in X++ are translated into T-SQL statement sent to SQL Server.


1. join in X++:
select AccountNum from custTable
    join TaxGroupId from custGroup
    where custGroup.CustGroup == custTable.CustGroup;
CROSS JOIN in T-SQL:
SELECT T1.ACCOUNTNUM, T1.RECID, T2.TAXGROUPID, T2.RECID
FROM CUSTTABLE T1 CROSS JOIN CUSTGROUP T2
WHERE ((T1.PARTITION=?) AND (T1.DATAAREAID=?))
  AND (((T2.PARTITION=?) AND (T2.DATAAREAID=?)) 
   AND (T2.CUSTGROUP=T1.CUSTGROUP))

2. outer join in X++:
select AccountNum from custTable
    outer join AccountID from custBankAccount
    where custBankAccount.CustAccount == custTable.AccountNum;
LEFT OUTER JOIN in T-SQL:
SELECT T1.ACCOUNTNUM, T1.RECID, T2.ACCOUNTID, T2.RECID
FROM CUSTTABLE T1 LEFT OUTER JOIN CUSTBANKACCOUNT T2
ON (((T2.PARTITION=?) AND (T2.DATAAREAID=?))
AND (T1.ACCOUNTNUM=T2.CUSTACCOUNT))
WHERE ((T1.PARTITION=?) AND (T1.DATAAREAID=?))

3. exists join in X++:
select AccountNum from custBankAccount
    exists join custTable
    where custBankAccount.CustAccount == custTable.AccountNum;
EXISTS (SELECT 'x'...) in T-SQL:
SELECT T1.ACCOUNTNUM, T1.RECID
FROM CUSTBANKACCOUNT T1
WHERE ((T1.PARTITION=?) AND (T1.DATAAREAID=?))
AND EXISTS (SELECT 'x'
            FROM CUSTTABLE T2
            WHERE (((T2.PARTITION=?) AND (T2.DATAAREAID=?))
              AND  (T1.CUSTACCOUNT=T2.ACCOUNTNUM)))

4. notexists join in X++:
select AccountNum from custBankAccount
    notexists join custTable
    where custBankAccount.CustAccount == custTable.AccountNum;
NOT (EXISTS (SELECT 'x'...)) in T-SQL:
SELECT T1.ACCOUNTNUM, T1.RECID
FROM CUSTBANKACCOUNT T1
WHERE ((T1.PARTITION=?) AND (T1.DATAAREAID=?))
AND NOT (EXISTS (SELECT 'x'
                 FROM CUSTTABLE T2
                 WHERE (((T2.PARTITION=?) AND (T2.DATAAREAID=?))
                   AND  (T1.CUSTACCOUNT=T2.ACCOUNTNUM))))

5. join after exists join in X++:
select AccountNum from custBankAccount
    exists join custTable
    where custBankAccount.CustAccount == custTable.AccountNum
    join TaxGroupId from custGroup
    where custGroup.CustGroup == custTable.CustGroup;
EXISTS (SELECT 'x'...CROSS JOIN...) in T-SQL:
SELECT T1.ACCOUNTNUM, T1.RECID
FROM CUSTBANKACCOUNT T1
WHERE ((T1.PARTITION=?) AND (T1.DATAAREAID=?))
AND EXISTS (SELECT 'x'
            FROM CUSTTABLE T2 CROSS JOIN CUSTGROUP T3
            WHERE (((T2.PARTITION=?) AND (T2.DATAAREAID=?)) 
               AND (T1.CUSTACCOUNT=T2.ACCOUNTNUM)) 
              AND (((T3.PARTITION=?) AND (T3.DATAAREAID=?)) 
               AND (T3.CUSTGROUP=T2.CUSTGROUP)))


6. exists join after exists join in X++:
select AccountNum from custBankAccount
    exists join custTable
    where custBankAccount.CustAccount == custTable.AccountNum
    exists join custGroup
    where custGroup.CustGroup  == custTable.CustGroup
       && custGroup.TaxGroupId == "Std";
EXISTS (SELECT 'x'... EXISTS (SELECT 'x'...)) in T-SQL:
SELECT T1.ACCOUNTNUM, T1.RECID
FROM CUSTBANKACCOUNT T1
WHERE ((T1.PARTITION=?) AND (T1.DATAAREAID=?))

AND EXISTS (SELECT 'x' FROM CUSTTABLE T2 
            WHERE (((T2.PARTITION=?) AND (T2.DATAAREAID=?)) 
               AND (T1.CUSTACCOUNT=T2.ACCOUNTNUM)) 
               AND EXISTS (SELECT 'x' 
                           FROM CUSTGROUP T3 
                           WHERE (((T3.PARTITION=?) AND (T3.DATAAREAID=?)) 
                              AND ((T3.CUSTGROUP=T2.CUSTGROUP) AND (T3.TAXGROUPID=?)))))

Conclusion
each exists join is considered as a separate statement, but any join after exists join is coupled or nested.

Monday, July 20, 2015

Ax2012 retrieve/subtract the date that 6 months before today

Below is the sample code to get the date :-

For normal date :-

toDate = dateMthFwd(today, -6);

For UTC date :-

toDate = DateTimeUtil::addMonths(today, -6);

Wednesday, July 15, 2015

AX2012 Generate number sequence by Number Sequence Code.

Below is the code for generate the num seq manually by num seq code:-
 
Public ShipId GenShipId()
{
NumberSeq       numberSeq;
NumberSequenceTable     numberSequenceTableNum;
;

//Not need to use the reference method
//NumberSeq = NumberSeq::newGetNum(PurchParameters::numRefShipInfoSeqCode(),true,False);
//"SHIP is the num seq code
NumberSequenceTableNum = NumberSequenceTable::findByNaturalKey("SHIP");//find(5637147045);

numberSeq = NumberSeq::newFromParameters(numberSequenceTableNum.Continuous);

numberSeq.parmNumberSequenceCode(numberSequenceTableNum.NumberSequence);
numberSeq.parmNumberSequenceId(numberSequenceTableNum.RecId);
numberSeq.parmNumTableNum(numberSequenceTableNum);
numberSeq.parmMakeDecisionLater(false);

//NumberSeq.used();
return  numberSeq.num();
}

Monday, April 6, 2015

Axapta retrieve the Sales Tax amount on Sales order/Purchase order

Axapta will store the sales tax amount on a temporary table before invoice the SO/PO. Hence we can direct retrieve the tax amount from table.

However, we would like to get the tax amount before invoice for adjustment or validations purpose. Hence below standard code can help us to overcome the temp table problem.

Ax2.5 - Ax2009 :-

TaxLedgerJournalCalculate::totalTaxAmountSingleLine(TaxJournalCall::Journal, _ledgerJournalTrans, 0, 0);  


Ax2012 :-

LedgerJournalEngine.taxAmountJournal(_ledgerJournalTrans);

Thursday, January 29, 2015

宫缩与阵痛感觉

大约在分娩前几个月,尤其是最后的几周,宫缩就已经开始了。有些人刚开始时还没感觉,只有用手去摸肚子时,才会感受到宫缩,而且孕妈妈会感觉宫缩频率越来越高。这种宫缩无规律性,了无周期性,也不会有疼痛感。

专家表示,一般计算宫缩时,如果每小时宫缩次数在10次左右就属于比较频繁的,应及时去医院,在医生指导下服用一些抑制宫缩的药物,以预防早产的发生。如果宫缩次数不是很频繁,没有腹痛,注意休息就可以了,切记不要自行用药。

阵痛是什么感觉?

阵痛是有规律性的,这个也是因人而异,你可能对疼痛会有不一样的感觉,有的人会感觉到全身疼痛,有的人会感到拉伸的疼痛,有的人则会压迫的疼痛,那是因为不同的原因导致的疼痛感。

造成阵痛的原因:

1、全身疼痛:由于胎儿挤压使子宫收缩,让全身都感觉疼痛。

2、拉伸的疼痛:胎儿要出生的时候子宫肌肉、阴道和会阴处等软产道被拉伸,能够感觉组织和皮肤被拉伸的疼痛。

3、压迫的疼痛:骨盆的神经被胎儿的头压迫着。腰、臀部、脚后跟都非常疼。

阵痛的感觉

1、肚子疼痛

产妇要了解产生阵痛的原因,就会理解阵痛的时候不仅仅会感觉到腹部的疼痛。阵痛是由于子宫收缩引起,因此连带腰部、臀部、脚后跟都会有被拉伸的感觉,子宫口和阴道也会非常疼。

2、肌肉紧痛

随着阵痛全身会感觉到越来越疼,因此要尽量放松自己的身体。

阵痛是有规律的

开始时:肚子有一种缓慢、迟钝的疼痛,腰部感觉有不规则的疼痛

变化中:疼痛的间隔变短了,疼痛也随着变强

规律化:逐渐你会发现阵痛慢慢地变得有规律了。每隔10分钟,阵痛时间会延长30秒,阵痛会变得越来越强

那么,分别了解了以上宫缩跟阵痛的感觉后,你是不是对宫缩跟阵痛有了更深的了解呢?下面我们来对比下他俩的区别与联系。

宫缩感觉与阵痛感觉的区别

阵痛是由宫缩引起的,是要生了的表现,而宫缩有生之前的宫缩,也有假性宫缩,晚上疼早上就会减轻或者消失,不会像阵痛那样越来越强烈。

宫缩感觉与阵痛感觉的联系

当你到了预产期,只有伴有阵痛的宫缩,才是分娩的先兆。

当宫缩引起你轻微的阵痛,一会儿过去了,渐渐阵痛有所加强,间隔缩短,阵痛时间延长。宫缩像浪潮一样涌来,阵阵疼痛向下腹扩散,或有腰酸下附排便感,这种宫缩是为宝宝出生作准备。所以这点阵痛算不了什么,只要和医生合作,利用你练习过的呼吸操配合宫缩,就能顺利度过分娩关。

Tuesday, January 27, 2015

Axapta 2012 import budget data from CSV

Below example is import budget data.

The import csv file as below :-



The import budget dialog as below :-



The result after imported as below :-


Below is the code to complete the import process :-

1. Create an EDT TECBudgetCode and extend from BudgetCode




2. Create a class named  ImportBudget 
3. Extend RunBase
4. Amend the code below in classDeclaration :-

public class ImportBudget extends RunBase
{
    DialogField             _dfFilePath, _dfBudgetCode, _dfBudgetModel, _dfCompany, _dfDate;
    TransDate               _defaultDate;
    BudgetCode              _budgetCode;
    BudgetModelId           _budgetModelId;
    SelectableDataArea      _company;
    Str                     _filePath;
    FormDateControl         _codeControl, _modelControl, _dateControl;
}

5. Create method Dialog as below :-

protected Object Dialog()
{
    Dialog          dialog;
    DialogGroup     parameterGp, fileGp;
    ;

    dialog = super();

    dialog.caption("Upload Budget");

    parameterGp     = dialog.addGroup("Parameters"); //group up the fields below 

    _dfBudgetCode   = dialog.addField(extendedTypeStr(TECBudgetCode));
    _codeControl    = _dfBudgetCode.control();
    _codeControl.mandatory(true); //set mandatory

    _dfBudgetModel  = dialog.addField(extendedTypeStr(BudgetModelId));
    _modelControl   = _dfBudgetModel.control();
    _modelControl.mandatory(true);

    _dfCompany      = dialog.addField(extendedTypeStr(SelectableDataArea));
    _dfCompany.value(curext()); //set default value

    _dfDate         = dialog.addField(extendedTypeStr(TransDate));
    _dateControl    = _dfDate.control();
    _dateControl.mandatory(true);

    fileGp          = dialog.addGroup("File");
    _dfFilePath     = dialog.addField(extendedTypeStr(FilenameOpen),"Select file","Select file to import");
    dialog.filenameLookupFilter(['csv','*.csv']);
    return dialog;
}

6. Create a new  boolean method named getFromDialog() to get the value :-

public boolean getFromDialog()
{
    _defaultDate    = _dfDate.value();
    _company        = _dfCompany.value();
    _budgetModelId  = _dfBudgetModel.value();
    _budgetCode     = _dfBudgetCode.value();
    _filePath       = _dfFilePath.value();
    return super();
}

7. Create method Run as below :-

public void run()
{
    AsciiIo                                               importFile;
    str                                                      filePath,fileNameOnly;
    filetype                                              type;
    container                                          record;
    str                                                     Delimiter = ",";
    int                                                     totalRecords;
    RecId                                                budgetCodeRecId;
    BudgetTransactionType                   budgetTransactionType;
    BudgetTransactionHeader               budgetTransHeader;
    boolean                                             ret;
    Date                                                  CustomDate;
    Int                                                     month_number;
    Int                                                     years_numbers;
    Int                                                     day_number;
    Int                                                     numofMonth;

    ;

     //get the file value
    [filePath, fileNameOnly, type] = fileNameSplit(_filePath);
    importFile = new AsciiIo(_filePath, 'R');

    if((!importFile) || (importFile.status() != IO_Status::Ok))
    {
        warning("@SYS52676");
        throw(Exception::Error);
    }

    importFile.inFieldDelimiter(Delimiter);
    if((!importFile) || (importFile.status() != IO_Status::Ok))
    {
        warning("@SYS52676");
        throw(Exception::Error);
    }

    try
    {
        ttsbegin;
        
        // check the number sequence setup in budget parameter
        ret = BudgetTransactionManager::checkBudgetTransactionNumberSequence();
        if(ret)
        {

            budgetCodeRecId         = BudgetTransactionCode::findByBudgetTransactionCode(_budgetCode).RecId;
            budgetTransactionType   = BudgetTransactionCode::findByBudgetTransactionCode(_budgetCode).BudgetTransactionType;

            budgetTransHeader.initValue();
            //get number seq value
            BudgetTransHeader.TransactionNumber     = NumberSeq::newGetNum(BudgetParameters::numRefBudgetTransactionId()).num();
            budgetTransHeader.BudgetModelDataAreaId = _company;
            budgetTransHeader.BudgetModelId         = _budgetModelId;
            budgetTransHeader.BudgetTransactionCode = budgetCodeRecId;
            budgetTransHeader.BudgetTransactionType = budgetTransactionType;
            budgetTransHeader.Date                  = _defaultDate;
            budgetTransHeader.insert();

        }

        years_numbers = year(_defaultDate);
        day_number    = 1;


        record = importFile.read();
        while(importFile.status() ==  IO_Status::Ok)
        {
            // budget amount start from January [conpeek(recrod,5)]
            numofMonth = 5;
            record = importFile.read();
            if(!record)
                break;

            //5 = Jan , 16 = Dec
            while(numofMonth <= 16)
            {

                customDate =mkdate(day_number, numofMonth - 4, years_numbers);
                totalRecords = totalRecords + 1;
                this.createBudgetTransactionLine(budgetTransHeader, record, numOfMonth, customDate, totalRecords);

                numofMonth++;
            }
        }

        ttscommit;
        info(strFmt("@TEC88", totalRecords));

    }

    catch(Exception::Error)
    {
        Throw(Exception::Error);
    }
}

8. Create a method named CreateBudgetTransactionLine for generate line data :-

private void createBudgetTransactionLine(BudgetTransactionHeader    _budgetTransHeader, container _record, int _numOfMonth, date _customDate, int _lineNumber)
{
    BudgetTransactionLine   budgetTransLine;
    Name                    accountStructureName;
    DimensionHierarchy      accountStructure;

    ;
    ttsBegin;
    budgetTransLine.clear();
    budgetTransLine.initFromBudgetTransactionHeader(_budgetTransHeader);
    accountStructureName = conPeek(_record,1);

    //get the accountsturcture
    accountStructure = DimensionHierarchy::find(DimensionAttributeValueCombination::find(DMFDimensionHelper::generateDynamicDimension(conPeek(_record,2))).AccountStructure);
    if(accountStructure.Name != accountStructureName)
    {
        throw error(strFmt("@DMF1586",accountStructure.Name,accountStructureName));
    }

    //get the financial dimension to recid
    budgetTransLine.LedgerDimension             = DMFDimensionHelper::generateDynamicDimension(conPeek(_record,2));
    budgetTransLine.TransactionCurrency         = conPeek(_record,3);
    budgetTransLine.BudgetType                  = conPeek(_record,4);
    budgetTransLine.TransactionCurrencyAmount   = decRound(conPeek(_record, _numofMonth),2);
    budgetTransLine.Date                        = _customDate;
    budgetTransLine.AccountingCurrencyAmount    = decRound(conPeek(_record,_numofMonth),2);
    budgetTransLine.LineNumber                  = _lineNumber;
    budgetTransLine.insert();
    budgetTransLine.clear();
    ttsCommit;
}


9. Create a main method:-

public static void main(Args _args)
{
    ImportBudget budgetCreate = new ImportBudget();

    if (budgetCreate.prompt())
    {
            budgetCreate.run();
    }
    
}

10. Done!!!

Axpata 2012 Convert financial dimension from value to recId

The code to get Financial dimension recid Id :-


Str dimension = "DAT-001-0003";
;

budgetTransLine.LedgerDimension             = DMFDimensionHelper::generateDynamicDimension(dimension);