Get latest information from inventdim having transactionid D365 - x++

can someone show me a easy way to get information from inventdim? I need to get batchid/ siteid/locationid for a project transaction. D365FO
I tried this select but I don't think its accurate enough
while select InventTransOrigin join salesline where SalesLine.InventTransId == InventTransOrigin.InventTransId
&& SalesLine.inventtransid == ProjItemTrans::find(projInvoiceItem.ProjTransId).inventtransid
join inventTrans where InventTrans.InventTransOrigin == InventTransOrigin.RecId
join inventdim order by inventdim.inventBatchId desc where InventDim.inventDimId == InventTrans.inventDimId

Related

eloquent get latest raw in join clause

I use laravel 5.2 I'm trying to get latest intervention of each foreing key pmt_id like bellow:
$res = $this->model->with('typo', 'nro', 'ctr', 'cad', 'pm')
->join('a2t_intervention',function ($join) use ($salar){
$join->on('a2t_intervention.pmt_id','=','a2t_pmt.id');
$join->whereRaw('a2t_intervention.pmt_id = (select max(`pmt_id`) from a2t_intervention)');
$join->where('a2t_intervention.etat_intervention','like','nok');
$join->whereIN('a2t_intervention.id_equipe_stt',$salar);
});
but I get this ERROR :
Call to undefined method Illuminate\Database\Query\JoinClause::whereRaw()
I try other ways but nothig work for me.
for each pmt_id in the table intervention we have at least one record ,I'am looking for get the last intervention foreach single pmt_id before make join with table PMT.
how to select id from table intervention in latest pmt_id like bellow in sql query:
SELECT t.*
FROM ( SELECT pmt_id
, MAX(id) AS id
FROM a2t_intervention
WHERE etat_intervention = 'nok'
AND `id_equipe_stt` IN ('" . implode(',', $id_equipe_stt) . "')
GROUP
BY pmt_id ) AS m
INNER JOIN a2t_intervention AS t
ON t.pmt_id = m.pmt_id
AND t.id = m.id
Error is pretty self-explanatory - there is no whereRaw method. You could try to replace:
$join->whereRaw('a2t_intervention.pmt_id = (select max(`pmt_id`) from a2t_intervention)');
with
$join->where('a2t_intervention.pmt_id', '=', \DB::raw("(select max(`pmt_id`) from a2t_intervention)"));
In Later Laravel versions JoinClause extends Builder so whereRaw method is available but for Laravel 5.2 it isn't.

Select 1 as one - Ruby Queries rolls back in staging and prod

I am trying to update the quantity of the products table after the payment has succeeded on my rails app.
This is how I am doing it,
#orders1 = Order.where("shoppingcart_id" => #cart.id)
#orders1.each do |order|
#oproduct = Product.where("id" => order.product.id).first
if(#oproduct.quantity >=1 )
#oproduct.quantity = #oproduct.quantity - 1;
#oproduct.save
end
end
When I am looking into the query logs, I see Ruby runs this select 1 as one query -
Product Exists (1.6ms) SELECT 1 AS one FROM "products" WHERE
"products"."name" = ? AND "products"."id" != ? LIMIT ?
On my local (SQLLite), it works fine without any rollbacks and my product quantity gets updated correctly.
But when I run the same on staging, it fails. The transaction rolls back.
On one other local machine, it fails as well. I am not able to reproduce this on my local and not sure why this is happening either. The other updates are working perfectly fine, like orders update. Only the product quantity update fails.
Is that product exists query mandatory? Not sure if I am missing any setting for my staging or is there any problem with the code.
Try this.
#product = Product.find(order.product.id)
if #product.quantity > 0
#product.update_attributes!(quantity: #product.quantity -1)
end

SQLite.swift joins missing information

I am trying to join a few tables in swift using the SQLite.swift library and I am having a few problems. The below code shows the issue:
I first join the tables:
let ext_tasks = tasks.join(tasktypes, on: tasktypes[tty_id] == tasks[task_type])
.join(preUsers, on: preUsers[Worker_ID] == task_ownerID)
.order(task_dueDate)
.filter(task_ownerID == iUserID)
At this point I have the tables joined and all the fields from tasks, task types and preUsers are there properly.
Following I run the second join statement:
let ext_equipment = equipment.join(equipment_type, on: equipment_type[eqt_id] == equipment[equ_type])
.join(facilities, on: facilities[fac_id] == equipment[equ_facid])
.join(eqowners, on: eqowners[Worker_ID] == equipment[equ_owner])
.order(equ_make)
.filter(equ_status >= 0)
Again, after running this statement I can access all the fields from the equipment, equipment_type, facilities and eqowners tables, up to here everything is working as expected...
However then I try to join the two above results using:
let comp_tasks = ext_tasks.join(ext_equipment, on: ext_equipment[equ_id] == ext_tasks[task_eqID])
.order(task_dueDate)
Here is where I run into a problem, it seems like the tables coming from the ext_tasks query are there but only the equipment table from the ext_equipment query is available.
Further when I try to access the "facilities"."facility_name" field, I get the following message saying that the field does not exist:
fatal error: no such column '"Facilities"."Facility_Name"' in columns:
["Equipment"."EquipmentType_ID", "Equipment"."Equipment_ID", "Equipment"."Equipment_Owner_ID", "Equipment"."Facility_ID", "Equipment"."Status", "PreUsers"."Client_ID", "PreUsers"."Date_LastLogin", "PreUsers"."First_Name", "TaskTypes"."TaskType_ID", "TaskTypes"."Type", "Tasks"."Equipment_ID", "Tasks"."Owner_ID", "Tasks"."Priority", "Tasks"."Time_Complete", "Tasks"."Time_Start"]:
(I removed some of the columns in there to shorten the answer, there are 53 fields in total shown) but as you can see only tables from the first join + the equipment table are shown, the joins from the second query (equipment_type, facilities and eqowners) are nowhere to be seen
I would appreciate if someone could let me know why this is happening, this has been killing my brain for hours and I just can't figure it out...
Thanks in advance!

Query - Does Not Contain

I have a search query to lookup Customers.
I would like to use the Sounds Like function to return additional possible results, however this is returning some of the same results in my main search query.
I would like to only show the additional results in a partial view.
I basically need a DoesNotContain.
Here is what I have so far for my main query:
customer = customer.Where(c => SqlFunctions.StringConvert((double)c.CustomerID).Trim().Equals(searchString)
|| c.CustomerName.ToUpper().Contains(searchString.ToUpper()));
And for the additional results:
customeradditional = customeradditional.Where(c => SqlFunctions.SoundCode(c.CustomerName.ToUpper()) == SqlFunctions.SoundCode(searchString.ToUpper()));
The only possible solution I can see at the minute is to do a Contains Query, loop through each item and get the IDs, then do another query for CustomerID != 1 or CustomerID != 2 or CustomerID != 3, etc.
Try using Except:
customeradditional = customeradditional
.Where(c => SqlFunctions.SoundCode(c.CustomerName.ToUpper()) == SqlFunctions.SoundCode(searchString.ToUpper()))
.Except(customer);
I am not sure if I understood you correct:
From what you have now, the customeraddtional query does return some of the customers already returned in the customer query. And you only want the results, which are not already contained in the customer query.
Then the solution would be:
customeradditional = customeradditional.Where(c =>
SqlFunctions.SoundCode(c.CustomerName.ToUpper()) ==
SqlFunctions.SoundCode(searchString.ToUpper()))
.Except(customer);
This way your are explicitly excluding every item, which is present in the customer object.

SCCM 2007 Report to check servers time zone

I need to create a SCCM 2007 report to check the time zone over a specific collection. I found something to do this, but is not working when i insert it in the Report SQL Statement.
select SMS_R_System.Name, SMS_R_System.SMSAssignedSites, SMS_R_System.IPAddresses, SMS_R_System.IPSubnets, SMS_R_System.OperatingSystemNameandVersion, SMS_R_System.ResourceDomainORWorkgroup, SMS_R_System.LastLogonUserDomain, SMS_R_System.LastLogonUserName, SMS_R_System.SMSUniqueIdentifier, SMS_R_System.ResourceId, SMS_R_System.ResourceType, SMS_R_System.NetbiosName, SMS_G_System_COMPUTER_SYSTEM.CurrentTimeZone from SMS_R_System inner join SMS_G_System_COMPUTER_SYSTEM on SMS_G_System_COMPUTER_SYSTEM.ResourceID = SMS_R_System.ResourceId where SMS_G_System_COMPUTER_SYSTEM.CurrentTimeZone != -360 order by name
For a report you need to use the database views, see below for a quickly modified query which should do what you need:
select
v_R_System.Name0,
v_GS_COMPUTER_SYSTEM.CurrentTimeZone0
from v_R_System
inner join v_GS_COMPUTER_SYSTEM on v_GS_COMPUTER_SYSTEM.ResourceID = v_R_System.ResourceId
join v_FullCollectionMembership ON v_FullCollectionMembership.ResourceID = v_R_System.ResourceID
where
v_GS_COMPUTER_SYSTEM.CurrentTimeZone0 != -360
AND v_FullCollectionMembership.CollectionID = '<yourcollectionid>'
order by Name0
Just replace "<yourcollectionid>" with the id you want to query.

Resources