how to create two number sequences - axapta

Can we create Purchase order Number Sequence with the division capture for Local and Foreign purchases?
Can we create two number sequence at a time in AX 2012 ?

Yes you can.
Not knowing anything about your version or what you have done or tried, I will try guessing you are using AX 2012.
Then go looking in \Classes\CustPostInvoice\run on how they set the invoiceId variable.
if (countryRegion_LTLV)
{
[invoiceId, voucher] = this.getNumAndVoucher_W(numberSeq);
}
else
{
[invoiceId, voucher] = numberSeq.numAndVoucher();
}
It even looks more ugly, but the point is, use two different number sequences, then use an if to choose the right one.
Maybe you should also read about setting up a new number sequence?

Related

Snowflake, Python/Jupyter analysis

I am new to Snowflake, and running a query to get a couple of day's data - this returns more than 200 million rows, and take a few days. I tried running the same query in Jupyter - and the kernel restars/dies before the query ends. Even if it got into Jupyter - I doubt I could analyze the data in any reasonable timeline (but maybe using dask?).
I am not really sure where to start - I am trying to check the data for missing values, and my first instinct was to use Jupyter - but I am lost at the moment.
My next idea is to stay within Snowflake - and check the columns there with case statements (e.g. sum(case when column_value = '' then 1 else 0 end) as number_missing_values
Does anyone have any ideas/direction I could try - or know if I'm doing something wrong?
Thank you!
not really the answer you are looking for but
sum(case when column_value = '' then 1 else 0 end) as number_missing_values`
when you say missing value, this will only find values that are an empty string
this can also be written is a simpler form as:
count_if(column_value = '') as number_missing_values
The data base already knows how many rows are in a column, and it knows how many null columns there are. If loading data into a table, it might make more sense to not load empty strings, and use null instead then, for not compute cost you can run:
count(*) - count(column) as number_empty_values
also of note, if you have two tables in snowflake you can compare the via the MINUS
aka
select * from table_1
minus
select * from table_2
is useful to find missing rows, you do have to do it in both directions.
Then you can HASH rows, or hash the whole table via HASH_AGG
But normally when looking for missing data, you have an external system, so the driver is 'what can that system handle' and finding common ground.
Also in the past we where search for bugs in our processing that cause duplicate data (where we needed/wanted no duplicates) so then the above, and COUNT DISTINCT like commands come in useful.

How to Add Column (script) transform that queries another column for content

I’m looking for a simple expression that puts a ‘1’ in column E if ‘SomeContent’ is contained in column D. I’m doing this in Azure ML Workbench through their Add Column (script) function. Here’s some examples they give.
row.ColumnA + row.ColumnB is the same as row["ColumnA"] + row["ColumnB"]
1 if row.ColumnA < 4 else 2
datetime.datetime.now()
float(row.ColumnA) / float(row.ColumnB - 1)
'Bad' if pd.isnull(row.ColumnA) else 'Good'
Any ideas on a 1 line script I could use for this? Thanks
Without really knowing what you want to look for in column 'D', I still think you can find all the information you need in the examples they give.
The script is being wrapped by a function that collects the value you calculate/provide and puts it in the new column. This assignment happens for each row individually. The value could be a static value, an arbitrary calculation, or it could be dependent on the values in the other columns for the specific row.
In the "Hint" section, you can see two different ways of obtaining the values from the other rows:
The current row is referenced using 'row' and then a column qualifier, for example row.colname or row['colname'].
In your case, you obtain the value for column 'D' either by row.D or row['D']
After that, all you need to do is come up with the specific logic for ensuring if 'SomeContent' is contained in column 'D' for that specific row. In your case, the '1 line script' would look something like this:
1 if [logic ensuring 'SomeContent' is contained in row.D] else 0
If you need help with the logic, you need to provide more specific examples.
You can read more in the Azure Machine Learning Documentation:
Sample of custom column transforms (Python)
Data Preparations Python extensions
Hope this helps

Subtract payment until amount due is zero

Using powershell I read in a text file that contains the check amount. I then create a query and get the amount due. The problem comes in because buyer could have multiple balances for different products. So they could write a check that covered A but not B and C.
$remainAmount = $currentAmount[0] - $checkAmount
How can I do this and not produce a negative number, force it to stop subtracting when zero is reached?
One solution would be to use the [Math]::Max() function like this:
$remainamount = [Math]::Max($currentamount[0] - $checkamount,0)
That will give you the higher of the two numbers, so if they still owe something it gives that, or it gives 0.

Strange QTableWidget behavior - not all cells populated after sorting followed by repopulating

I have a QTableWidget that I populate like this:
// Clear the table
this->topPatchesTableWidget->setRowCount(0);
this->topPatchesTableWidget->setRowCount(numberToDisplay);
for(unsigned int pairId = 0; pairId < numberToDisplay; ++pairId)
{
// Display patch match scores
QTableWidgetItem* myLabel = new QTableWidgetItem;
myLabel->setData(Qt::DisplayRole, myValues[pairId]);
this->tableWidget->setItem(pairId, 0, myLabel);
... fill other columns ...
}
(I have some other UI elements to set properties that compute the values in myValues). If I change the properties, recompute, and recreate the table, everything works as expected. If I sort the table by clicking on one of the headers, it sorts correctly. HOWEVER, if at this point (after sorting) I click my button again to recompute the values and recreate the table, the table is very broken. That is, many of the cells are empty, and the cells that are not empty don't seem to be in any particular order.
By adding a manual call to
this->tableWidget->sortByColumn(0, Qt::AscendingOrder);
at the beginning of my CreateTable function, everything works as expected, but of course the newly created table is sorted by column 0 rather than the column that was selected for the last sort.
Does anyone have any idea why things would go so wrong without the call to sortByColumn? (I tried to make a simple example but I can't replicate the problem in a demo program).
Thanks,
David
I had a similar problem in python, if a column header was selected to enable sorting the cells after that column stopped populating.
I got around it by setting self.tableWidget.setSortingEnabled(False) at the beginning of the row add method, then setting it back to self.tableWidget.setSortingEnabled(True) at the end of the row add method. According to riverbank computing this is the officially recommended way to address this problem.
QTableWidget.setItem (self, int row, int column, QTableWidgetItem item)
Note that if sorting is enabled (see sortingEnabled) and column is the current sort column, the row will be moved to the sorted position determined by item.
If you want to set several items of a particular row (say, by calling setItem() in a loop), you may want to turn off sorting before doing so, and turn it back on afterwards; this will allow you to use the same row argument for all items in the same row (i.e. setItem() will not move the row).
See also item() and takeItem().
This is an elaboration on Karnisov's answer, also with PyQt. Disabling sorting before doing any setItem()s also worked for me, but it caused the user's sort selection to be lost, so I did it like this, where t is a QTableWidget:
oldSort = t.horizontalHeader().sortIndicatorSection()
oldOrder = t.horizontalHeader().sortIndicatorOrder()
t.setSortingEnabled(False)
# make the changes
t.sortItems(oldSort, oldOrder)
t.setSortingEnabled(True)
Note that it is still possible for the sort to change slightly with this code. This appears to be because the sort that Qt is using here doesn't move any items that were already in order, so if we had a table like this:
NUMBER LETTER OTHER LETTER
1 B C
2 G Q
3 A Q
If we sort by NUMBER, then by OTHER LETTER, nothing changes. But if we sort by LETTER, then by OTHER LETTER, we get:
NUMBER LETTER OTHER LETTER
1 B C
3 A Q
2 G Q
So if we had previously sorted by LETTER, then OTHER LETTER, this code would only do a single sort by OTHER LETTER, and we'd end up with the second version of the table instead of the first (assuming that the order the elements were added to the table in matches NUMBER). In this spot in my code, all items are deleted and re-added to refresh the table, so this can sometimes cause noticeable changes in order.
I had the same problem - always, when I wanted to insert new data, i buildet the header and setSortingEnabled(true). I guess the QTableWidget does not like several calls for setSortingEnabled(true). So I put it into the constructor of my MainWindown, and thats it!
I never figured out what was wrong with this. I gave up and implemented a custom model/view which is probably a much better idea anyway.

MPXJ: get planned work via API

I want to extract the planned work over the time from MS Project using MPXJ.
Does anyone know how to get these figures via API?
I cannot find any appropriate method for doing this.
(Concrete scenario: I want to draw a chart with the planned work on the y-axis and the date on the x-axis)
The answer Jon gave above was correct at the time, but as of version 4.2 of MPXJ, the api for dealing with timephased work (and cost) has been changed considerably. Here's what you would do now:
This part's the same:
TimescaleUtility timescale = new TimescaleUtility();
ArrayList<DateRange> dateList = timescale.createTimescale(startDate, TimescaleUnits.DAYS, length);
This has changed (notice the different return type and method for getting the planned work, and the new method on the TimephasedUtility class):
List<TimephasedWork> plannedWork = assignment.getTimephasedWork();
ProjectCalendar calendar = assignment.getCalendar();
TimephasedUtility util = new TimephasedUtility();
ArrayList<Duration> durationList = util.segmentWork(calendar, plannedWork, TimescaleUnits.DAYS, dateList);
One thing you also have to know is that the planned work data only contains values for work that has not been completed yet (ie, no actual values have been recorded for that time). For example, if your assignment lasts for 4 days, and you've completed 50% of the work, then you will have timephased ACTUAL work values for the first two days, and timephased PLANNED work values only for the last two days. They do not overlap or duplicate.
So if you are trying to show planned work values for the whole time period of the assignment (like what you'd see in the Task Usage views in MS Project), you'd need to also retrieve the timephased actual work values and use them as if they were planned work too.
your starting point is the following methods on the assignment object:
List<TimephasedResourceAssignment> complete = assignment.getTimephasedComplete();
List<TimephasedResourceAssignment> planned= assignment.getTimephasedComplete();
As their names suggest, these will get you either the planned work or the complete work, expressed as work carried out over periods of time.
The "gotcha" here is that this data is represented in a compact format (reflecting how it's stored by MS Project internally), and this does not lend itself well to showing a period-by-period breakdown of work.
To get what you want, there are two utility classes which will help you to convert this compact representation into a list of work values. For example, you can give them a start date a period type (day, week, month and so on) and a number of periods, and ask for the work to be broken down over these periods.
First step is to create an instance of the TimescaleUtility class, and get it to generate a range of dates for you. You give it the start date, the timescale units you require, and the numnber of periods you want.
TimescaleUtility timescale = new TimescaleUtility();
ArrayList<DateRange> dateList = timescale.createTimescale(startDate, TimescaleUnits.DAYS, length);
The dateList variable now contains the list of date ranges you are going to split the work over. This split is carried out using the TimephasedUtility class:
ProjectCalendar calendar = assignment.getCalendar();
TimephasedUtility timephased = new TimephasedUtility();
ArrayList<Duration> durationList = timephased.segmentResourceAssignment(calendar, planned, TimescaleUnits.DAYS, dateList);
That's it, your durationList now contains one entry for each entry in the datList showing the amount of work for that period.
Hope that makes sense!
Jon

Resources